I cannot use the Active Directory Module to get the SamAccountName of the users in a specific AD-group. How can I do this with ADSI?
I've tried:
$Group = [ADSI]"LDAP://DN of the AD group"
$Group.Member | ForEach-Object {
$Searcher = [adsisearcher]"(samAccountName=$_)"
$searcher.FindOne().Properties
}
But I see this message:
The samAccountName search filter is invalid.
How can I do this?
There are 2 ways around this as I see it, there might be an easier way of doing it though.
One is to search for all users which's
memberOfattribute has theDistinguishedNameof the group (this might be the less cumbersome approach):The other way around is using the same approach as you're using in your question:
Similar as the one above, but using
adsisearcher, not sure which one would be more efficient in this case: