I’ve got this code from a post here, which works perfectly:
Import-CSV $file | % {$myGroup | Add-ADGroupMember -Members $_.Alias}
The first line of my CSV file is “alias” and every other line is a username. This works great.
However when I modify the code to this:
Import-CSV $file | % {$myGroup | Add-ADGroupMember -Members $_.displayName}
And I modify the CSV file first line to “displayName” and every other line to a display name, it doesn’t work. I’m guessing this is because displayName is not a valid property for this code, so how can I modify this to use the display name of a user instead of the username?
That won’t work because DisplayName is not an accepted value. Here’s a list of valid values. See the cmdlet online help here: http://technet.microsoft.com/en-us/library/ee617210.aspx
In addition, the Members parameter accept a collection of values so you could also do this: