Import-Csv -Path "F:\Temp\Users.csv" |
ForEach-Object {If($_.Name -ne "") {Add-ADGroupMember -Identity "Test Group" `
-Members $_.Name}}
We first import the CSV file into the PowerShell pipeline. Next we pass the object to a ForEach-Object statement. Each object is tested to see if the name property is empty. If it is, then nothing is done. If it contains data, then the user is added to the group. I could not use Where-Object {$_.Name –ne “”} as my filter because Add-ADGroupMember does not accept input from the PowerShell pipeline for its Member parameter.
No comments:
Post a Comment