I am trying to make a very simple script work that reads a CSV with 100 SamAccountName/Identities into a variable and then returns AD Users with all Objects from Get-ADUser.
The CSV only contains usernames (1 each line) so essentially it could also be a simple text file.
I feel like I'm very close but I can't make it work for some reason.
$users= (Import-CSV 'C:\Temp\users.csv') # <-- Doesn't work
#$users= "backupservice","name01" <-- This Works
ForEach ($user in $users)
{
Get-ADUser $user -Properties *
}
Here's the error message when I am trying to read the CSV into the loop:
Get-ADUser : Cannot validate argument on parameter 'Identity'. The Identity property on the argument is null or empty.
At line:8 char:16
+ Get-ADUser $user -Properties *
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Okay, so I have an issue with parameter binding but I am not sure how to fix it.
I would appreciate any input/insight you could give me.
Thank you!
I actually just now took the original CSV (which had two columns [SamAccountName and UPN]) and fixed it just now with the following code:
$users = (Import-CSV "C:\Temp\Test001.csv" | Select SamAccountName -ExpandProperty SamAccountName)
ForEach ($user in $users)
{
Get-ADUser $user -Properties * #| Export-CSV 'C:\Temp\users_expanded.csv'-Append
}
Is there a better way to do this? The journey continues.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.