2

I have the below script pulling the correct information, but need assistance formatting it. What I am looking for is a table that lists the Group names in Column A and the User names in Column B. The output right now lists the group names in Column A, but puts the user names all on one line in Column B.

This is what comes out:

Col A      Col B

Group1     {User 1, User 2, User 3}

This is what I would like to see:

Col A      Col B

Group 1    User 1

           User 2

           User 3

Here is the script I have thus far.

Get-QADGroup -Name '*Group Name*' | ForEach-Object {

$group = $_
$member = $group | Get-QADGroupMember -IncludedProperties samaccountname -UseDefaultExcludedProperties $true -SizeLimit 0

New-Object -TypeName PSObject -Property @{
    Name = $group.Name
    EID = $member
    }
}
4

1 回答 1

1

Not the format you asked for, but will group the members by group: (Updated to include SamAccountName)

Get-QADGroup -Name '*Application*' | `
% { $group = $_.Name; $_; } | ` 
Get-QADGroupMember | `
Select-Object @{n='Group';e={$group}}, Name, SamAccountName | `
Sort-Object Group | `
Format-Table Name, SamAccountName -GroupBy Group

If you really need the format exactly as asked for, one way you could get it is to order, then keep track of the previous group value, and if it is the same, mark it as empty, something like:

Get-QADGroup -Name '*Application*' | `
% { $group = $_.Name; $_; } | ` 
Get-QADGroupMember | `
Select-Object @{n='Group';e={$group}}, @{n='Member';e={$_.Name}} | `
Sort-Object Group | `
ForEach-Object {

$currentGroup = $_.Group

if ($currentGroup -eq $previousGroup)
{
 $_.Group = [string]::Empty
}

$previousGroup = $currentGroup
Write-Output $_
} | Format-Table
于 2013-05-06T15:04:55.820 回答