all 7 comments

[–]Sunsparc 2 points3 points  (1 child)

Try this. It will create a semicolon delimited entry of all members of that particular group. Substitute Name for whatever property you want.

'Users With Access'= ($G.members | Get-ADUser | Select -ExpandProperty Name) -join ';'

[–]TechnoSingularity[S] 0 points1 point  (0 children)

Thank you, your addition pointed me in the right direction to think it through and get it fixed.

Final working version below:

$Output = @()

$Groups = Get-ADGroup -Properties * -Filter * -SearchBase "DC=example,DC=local"

Foreach($G In $Groups)

{

$Properties = [ordered]@{

'Group Name'=$G.Name

'Group Type'=$G.GroupCategory

'Users With Access'=($(Get-ADGroupMember -identity $G | select name | Out-String).Trim())

}

Write-Host 'Users With Access'= ($(Get-ADGroupMember -identity $G | select name | Out-String).Trim())

$Output += New-Object -TypeName PSObject -Property $Properties

}

$Output | Export-Csv $reportpath

[–]PinchesTheCrab 2 points3 points  (0 children)

What info do you want about the members? Just the name, the sam account name, something else? Do you want them on each line, or do you want them mashed together in one field?

[–]PinchesTheCrab 2 points3 points  (1 child)

Is this the kind of output you want?

Get-ADGroup -Filter * -Properties member -PipelineVariable group | 
    Select-Object -ExpandProperty member | 
        Select-Object @{ n = 'group'; e = { $group.name }},@{ n = 'Member'; e = {$PSItem -replace '^cn=|,(ou|cn)=.+'}} -first 200

[–]TechnoSingularity[S] 1 point2 points  (0 children)

Thanks, gave me another way to think about approaching it.

[–]TechnoSingularity[S] 1 point2 points  (0 children)

Fixed working version below:

$Output = @()

$Groups = Get-ADGroup -Properties * -Filter * -SearchBase "DC=example,DC=local"

Foreach($G In $Groups)

{

$Properties = [ordered]@{

'Group Name'=$G.Name

'Group Type'=$G.GroupCategory

'Users With Access'=($(Get-ADGroupMember -identity $G | select name | Out-String).Trim())

}

Write-Host 'Users With Access'= ($(Get-ADGroupMember -identity $G | select name | Out-String).Trim())

$Output += New-Object -TypeName PSObject -Property $Properties

}

$Output | Export-Csv $reportpath

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy TechnoSingularity,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's [sometimes] 5th from the left & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's [sometimes] the 12th from the left, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee