I have this code:
Import-CSV -Path 'C:\Users\me\Desktop\All_EXO.csv' | ForEach-Object {
Get-ADUser -Filter {UserPrincipalName -eq $($_.UserPrincipalName)} -Properties GivenName,sn,mail,department,AccountType,Team,JobCode| select GivenName,sn,mail,department,AccountType,Team,JobCode
}
…but it’s balking about an invalid Path, yet, I can see the contents of the csv (has a header, ‘UserPrincipalName’)
Olaf
May 26, 2022, 9:56pm
2
Could you please share the complete error message?
Get-ADUser : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.
Olaf
May 27, 2022, 2:44pm
4
Try it this way:
Import-CSV -Path 'C:\Users\me\Desktop\All_EXO.csv' |
ForEach-Object {
$upn = $_.UserPrincipalName
Get-ADUser -Filter "UserPrincipalName -eq '$upn'" -Properties GivenName,sn,mail,department,AccountType,Team,JobCode |
Select-Object -Property GivenName,sn,mail,department,AccountType,Team,JobCode
}
1 Like
Olaf:
Import-CSV -Path 'C:\Users\me\Desktop\All_EXO.csv' |
ForEach-Object {
$upn = $_.UserPrincipalName
Get-ADUser -Filter "UserPrincipalName -eq '$upn'" -Properties GivenName,sn,mail,department,AccountType,Team,JobCode |
Select-Object -Property GivenName,sn,mail,department,AccountType,Team,JobCode
}
Thanks Olaf…Can you share briefly how you approached this solution for my edification?
Olaf
May 27, 2022, 3:25pm
6
I pasted the error message you posted into the search box of Google and clicked the first hit.
Which was this:
ah, “they need to be properly wrapped with quotes.”
Yeah I google too (a lot) but I doubt I woulda found it before Powershell.org !
thanks again
Olaf
May 27, 2022, 3:58pm
8
The type of the parameter -Filter is [string]. Even though PowerShell in general and the cmdlet Get-AdUser in particular are actually very forgiving you cannot use a scriptblock with variable substitution for it. The variable has to be expanded before.
1 Like