Reputation: 221
I would like to get a single output of the following two commands. In my head I think of SQL joins on the DN's here but I'm at a loss of what to do to combine these.
I would like to get the "Name" from Get-ADGroup for column A and the "Name" for Get-ADUser for column B. In SQL I could do this by joining on ManagedBy from Get-ADGroup and DistinguishedName from Get-ADUser. I hope that was clear enough...
Query 1
Get-ADGroup -Filter 'GroupCategory -eq "Security"' -Properties ManagedBy | Select Name,ManagedBy
Result 1
Accounts-SG CN=John Doe,OU=Users,OU=Accounting,OU=Corp,OU=Corporate,OU=Bozeman,OU=Montana,OU=US,OU=NA,DC=ad,DC=yourdomain,DC=com
Query 2
Get-ADUser -identity John.Doe | select Name, DistinguishedName
Result 2
John Doe CN=John Doe,OU=Users,OU=Accounting,OU=Corp,OU=Corporate,OU=Bozeman,OU=Montana,OU=US,OU=NA,DC=ad,DC=yourdomain,DC=com
Desired Result (Get-ADGroup Name + Get-ADUser Name
Accounts-SG John Doe
Please help, -Rob
Upvotes: 3
Views: 2254
Reputation: 6491
I've run into this problem before, and there isn't a super nice way built in. In the past, I've used this script, Merge-Csv.ps1, and it's worked well for me.
However, maybe you could use calculated properties to swap out the DistinguishedName
for their Name
?
So something like:
Get-ADGroup -Filter 'GroupCategory -eq "Security"' -Properties ManagedBy | Select Name, @{Name="ManagedByName";Expression={Get-AdUser -Identity "$_" | Select -Expand Name}}
Upvotes: 4