Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Help with a Script listing AD Groups and their Members

$
0
0

Total newbie to Powershell warning.

Trying to write a script to give me AD Groups and their members and export it out to some type of csv or txt file.

Looked up a script online and trying to make it work for my given circumstances.

Import-Module ActiveDirectory $Groups = Get-ADGroup -Properties * -Filter * -SearchBase “OU=MSG Groups,DC=mainstreetgourmet,DC=com” | select name

$Table = [ordered]@{ “Group Name”=”” “Name”=”” }

Foreach($Group in $Groups) { $Arrayofmembers = Get-ADGroupMember -identity $Group | select name

Foreach($Member in $Arrayofmembers) { $Record.”Group Name” = $Group $Record.”Name” = $Member.name $Record = New-Object PSObject -Property $Record $Table += $objrecord

}

}

$Table | Export-Csv “C:tempGroups.csv” -NoTypeInformation

I believe the error I am experiencing is caused by the $Table being created. I looked up other examples and it seems that I am not creating that table in a correct fashion and that is affecting the ‘Foreach($Member in $Arrayofmembers) for loop.

Not looking for out and out answers but guidance really.

Any advice is greatly appreciated.

submitted by /u/dynot
[link] [comments]

The post Help with a Script listing AD Groups and their Members appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793