Question

I have a small script in powershell written to query user groups in a specific OU in AD to get the name of those groups and to also try and get the ManagedBy attribute of those groups. I've been searching online and here for solutions to why the ManagedBy attribute is not populated results but I have had no luck. Every solution I have found has been written in C# (or another language) and I have tried using the Quest software for AD which doesn't seem to help.

$test = 'OU=example,DC=example,DC=test'

$test | ForEach {Get-ADGroup -Filter * -Properties ManagedBy -SearchBase $_ } | Select Name, Properties | Sort -Property Name | Out-File C:\test.csv

I am only getting results of the name of the groups and empty brackets for the ManagedBy attribute. My question is, is there anyway to query the managedby attribute in powershell without using another language or integrating different plugins? I've never written in C and I would prefer using native powershell if possible.

Was it helpful?

Solution

You've got an error in your Select. Properties should be ManagedBy.

$test = 'OU=example,DC=example,DC=test'

$test | ForEach {Get-ADGroup -Filter * -Properties ManagedBy -SearchBase $_ } |
 Select Name, ManagedBy |
 Sort -Property Name |
 Out-File C:\test.csv
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top