Powershell AD group
To list the AD groups users detail.
$nameofgroup= 'groupname'
$groupsusers=Get-ADGroup -Identity $nameofgroup |
ForEach-Object{
$settings=@{Group=$_.DistinguishedName;Member=$null}
$_ | Get-ADGroupMember |
ForEach-Object{
$settings.Member=$_.Name
New-Object PsObject -Property $settings
} }
$groupsusers | Export-Csv $env:USERPROFILE\desktop\GroupsUsers.csv –NoTypeInformation
---
Import-Module ActiveDirectory
$Groups = (Get-AdGroup -filter * | Where {$_.name -like "**"} | select name -ExpandProperty name)
$Table = @()
$Record = @{
"Group Name" = ""
"Name" = ""
"Username" = ""}
Foreach ($Group in $Groups) {
$Arrayofmembers = Get-ADGroupMember -identity $Group -recursive | select name,samaccountname
foreach ($Member in $Arrayofmembers) {
$Record."Group Name" = $Group
$Record."Name" = $Member.name
$Record."UserName" = $Member.samaccountname
$objRecord = New-Object PSObject -property $Record
$Table += $objrecord } }
$Table | export-csv "$env:userprofile\desktop\SecurityGroups.csv" -NoTypeInformation
Comments
Post a Comment