I’ve been trying to use the code below to get the list of AD groups that a target machine is in, but I am having some difficuly.
Get-AdComputer -Identity $hostname -property "MemberOf"
When I execute the code, I’m returned with this.
DistinguishedName : CN=$hostname,OU=test,OU=test,OU=test All Workstations,DC=te
st,DC=test,DC=com
DNSHostName : $hostname Enabled : True
MemberOf : {CN=Flash_Player_Adobe_11.1.102_LCL,OU=test All Softw
are Groups,DC=test,DC=test,DC=test, CN=Adobe Acrobat X P
rofessional 10,OU=test All Software Groups,DC=test,DC=test,D
C=co.uk, CN=Silverlight_Microsoft_4.0.60.0_LCL,OU=test
All Software Groups,DC=test,DC=test,DC=test}
Name : %hostname ObjectClass : computer
ObjectGUID : 5cf00026-c91a-422e-8a3e-7ee546456717f
SamAccountName : Test
SID : f-1-5-21-18934363546-5655752-5353453-564535
UserPrincipalName :
Is there a way I can just have memberOf returned (the list of AD agroups attached to the machine and ordered in a list with just the group name listsed. For example just:
Silverlight_Microsoft_4.0.60.0_LCL
Adobe Acrobat XP Professional
etc
You can use a regex to extract group names: