powershell issues with export

Welcome Forums General PowerShell Q&A powershell issues with export

Viewing 5 reply threads
  • Author
    Posts
    • #225414
      Participant
      Topics: 6
      Replies: 23
      Points: 35
      Rank: Member
      $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.

      • This topic was modified 3 weeks, 1 day ago by matthew moore. Reason: code block
      • This topic was modified 3 weeks, 1 day ago by matthew moore. Reason: correct fomatting
      • This topic was modified 3 weeks, 1 day ago by matthew moore. Reason: more context
    • #225426
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

      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 } 
          [PSCustomObject]@{
              Username  = $finalusernew
              IsPresent = if ($FinalUser) { $true }else { $false }
          }
      }
      $result

      You can pipe $result to Export-Csv.

    • #225438
      Participant
      Topics: 6
      Replies: 23
      Points: 35
      Rank: Member

      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

    • #225444
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

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

      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”? 😉

    • #225450
      Participant
      Topics: 6
      Replies: 23
      Points: 35
      Rank: Member

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

    • #225456
      Participant
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP

      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 😉 😀

Viewing 5 reply threads
  • You must be logged in to reply to this topic.