Amos
Amos

Reputation: 11

Powershell get aduser query by the emailaddress

I'm trying to get the AD user list query by email address. I managed to get the report however, I can't export it to a CSV file. I don't know which part gets wrong.

really much appreciate it if someone can guide me.

Thanks.

here is the script I made.


$ADUsers = Import-csv "C:\temp\DevicesWithInventory_6db9330a-4377-4057-bc86-837f55fee3f6.csv"
$email= $user.Primaryuseremailaddress

foreach ($user in $ADUsers) {

   get-aduser -Filter {emailaddress -eq $email} -Properties * | select name,mail, whencreated, company,cn,country 
   } | Export-Csv -path c:\temp\intune_add_country.csv -NoTypeInformation

   

Upvotes: 0

Views: 3029

Answers (1)

Amos
Amos

Reputation: 11

this is the amended script


$ADUsers = Import-csv "C:\temp\DevicesWithInventory_6db9330a-4377-4057-bc86-837f55fee3f6.csv"

$result = ForEach ($user in $ADUsers) {
    $email= $user.PrimaryuserUPN

   get-aduser -Filter {emailaddress -eq $email} -Properties * | select name,mail, whencreated, company,cn,country  
   }    
   
    $result| Export-Csv -path c:\temp\intune_add_country.csv -NoTypeInformation
  

despite the error, I get the report result that I want. error

Upvotes: 1

Related Questions