Hi guys,
I need your help with formatting output from my script.
The script is retrieving data from AD and showing it in a table. The problem is with users group membership,
it's displayed like @{Name="group name"} and I want it to be like "group name".
My script:
-------------------------------------------------------
$ou = "OU=EPC,DC=fr,DC=pri"
Get-ADUser -SearchBase $ou -Filter * -Properties LockedOut,Modified,DisplayName,Description,SamAccountName |
Select-Object -Property SamAccountName,Enabled,
@{n='Group Membership';e={Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($_.DistinguishedName))" | Select -Property Name}} | ft -AutoSize
-------------------------------------------------------
I'm retriving group membership with:
Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($_.DistinguishedName))" | Select -Property Name}
...becaues I also want nested groups.
This is my output now:
SamAccountName Enabled Group Membership
-------------- ------- ----------------
Read True {@{Name=Catalog-Read}, @{Name=Top-Group}}
Full True @{Name=Catalog-Full}
User3 True
svc-xxx True
svx True
...and this is what I want to get:
SamAccountName Enabled Group Membership
-------------- ------- ----------------
Read True Catalog-Read, Top-Group
Full True Catalog-Full
User3 True
svc-xxx True
svx True
Problem with output formatting
January 27th, 2015 1:12pm
This is the command you want to use:
https://technet.microsoft.com/en-us/library/ee617259.aspx
Free Windows Admin Tool Kit Click here and download it now
January 27th, 2015 3:00pm
Hi,
Here's something you can play with:
Get-ADUser -Filter * -Properties MemberOf -SearchBase 'OU=EPC,DC=fr,DC=pri' | Select SamAccountName,Enabled,@{N='Group Membership';E={ (($_.MemberOf | ForEach { Get-ADGroup $_ }).Name | Sort) -join ',' }} | Format-Table -AutoSize #Export-Csv .\groupMemberships.csv -NoTypeInformation
January 27th, 2015 5:08pm
Get-ADPrincipalGroupMembership is not giving me nested groups. Group Catalog-Read is in group Top-Group
and that is why I'm using Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($_.DistinguishedName))".
Free Windows Admin Tool Kit Click here and download it now
January 27th, 2015 6:39pm
This is not giving me nested groups but it's solving my formatting problem. There needs to be some way to combine my script with yours.
January 27th, 2015 6:43pm
This is not giving me nested groups but it's solving my formatting problem. There needs to be some way to combine my script with yours.
You can do anything you want inside the expression.
Free Windows Admin Tool Kit Click here and download it now
January 27th, 2015 6:52pm
In the Gallery are numerous scripts that get recursive group membership. You might want to start with one of those rather than incremntally adding requirements to your original question. Your question was about formatting and not about how to get
all nested groups.
January 27th, 2015 10:48pm
You are right. It took me some time to understand it but this is correct answer.
Free Windows Admin Tool Kit Click here and download it now
February 14th, 2015 12:18am
That's great, I'm glad it worked out for you.
February 14th, 2015 12:20am