powershell issues with export

$users = get-content "C:\Users\Public\bulk AD creation\users.txt"

foreach ($user in $users) {

$domain = "@xxx.org"

$finalusernew = $user + $domain

$FinalUser = Get-ADUser -Server "domain_server" -Filter {UserPrincipalName -eq $finalusernew} | select UserPrincipalName

#if (!$FinalUser) { Write-Host "$finalusernew is Missing" } Else { }

if (!$FinalUser) { Write-Host "$finalusernew is Missing" } Else { Write-Host User Does exist $finalusernew } #$FinalUser} }



i am not sure how to get the results to csv file.


here is the screen output


lindsey.alexander@xxx.org is Missing
User Does exist haley.arose@xxx.org
User Does exist brian.blevins@xxx.org
User Does exist amanda.bond@xxx.org
User Does exist rachelle.bowen@xxx.org

I have tried using export-csv and other methods and have failed.

Using Write-Host turns rich and powerfull objects into stupid pixels on the screen. Do not use it until you’re really sure you need it.

$users = get-content “C:\Users\Public\bulk AD creation\users.txt”
$result = foreach ($user in $users) {
$domain = “@xxx.org
$finalusernew = $user + $domain
$FinalUser = Get-ADUser -Server “domain_server” -Filter { UserPrincipalName -eq $finalusernew }
Username = $finalusernew
IsPresent = if ($FinalUser) { $true }else { $false }

You can pipe $result to Export-Csv.

thank you olaf. Is there any way to get the words in place of true or false. I have helpdesk people that are going to look for those words . True / False they might not understand even though i do.

write host was there so i could see the script working. But thanks for the heads up

Wow … helpdesk people do not understand true and false? Really? They might look for a better fitting job. :wink: :smiley:

You can see where the $true or $false is set, right? Just change it to whatever your helpdesk people can understand … maybe a simple “yes” and “no” or “there” and “gone”? :wink:

we call them the helpless desk … thank you so much .

lol … that was new for me … I will memorize this and use it when it fits … thanks :wink: :smiley: