troubleshooting Question

PowerShell - Get-ADUser, foreach-object

Avatar of Justin Hannah
Justin HannahFlag for Australia asked on
Active DirectoryShell ScriptingPowershell
4 Comments3 Solutions235 ViewsLast Modified:
Hi Experts,

Need a little help with PowerShell please.

Trying to get CanonicalName for each Object in my input csv file. It will have to export-csv also.

If I run this:

#Define files
$Source = 'C:\Temp\Exchange\AADSyncErrors\ExportErrors_2020_4_6_14_51_58_Filtered.csv'
$Output = 'C:\Temp\Exchange\AADSyncErrors\ExportErrors_2020_4_6_14_51_58_Filtered-Output.csv'

#Import CSV
Get-Content $Source | Foreach-object {
    Get-ADUser -Filter * -Properties CanonicalName,UserPrincipalName $_ | Export-CSV -Path $Output -Append 
}
I get error:
Get-ADUser : A positional parameter cannot be found that accepts argument 
User1

Get-ADUser : A positional parameter cannot be found that accepts argument 
User2

Get-ADUser : A positional parameter cannot be found that accepts argument 
User3
...

Thank you!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros