2013-06-26

取得 AD 群組成員的指令 Group Member List

Updated: 2017.02.17 ADD Powershell Script

基本: 取得群組成員的 (只能取得 Users, 不能取得 Groups)
  • net group /domain [Group Name]
進階: 取得巢狀群組所有成員 (包含 Users 與 Groups)
  • dsget group "CN=GroupName,DC=domain,DC=name,DC=com" -members -expand
或是使用以下 Powershell:

#-------------------------------------------------------
$Groups = @()
$Groups += "GroupName"
#-------------------------------------------------------
$Global:Users = @()
$Global:Groups = @()
Function Get-NestedGroupMember($Groups) {
$Groups | foreach {
Get-ADGroupMember -Identity $_ | select Name,ObjectClass -uniq | foreach {
if($_.ObjectClass -eq "Group") {
$Global:Groups += ($_.Name)
Get-NestedGroupMember($_.Name)
} else {
$Global:Users += ($_.Name)
}
}
}
}
Get-NestedGroupMember($Groups)
$Global:Groups = $Global:Groups | select -uniq
$Global:Users = $Global:Users | select -uniq
$GroupsResult =$Global:Groups | Out-String
$UsersResult =$Global:Users | Out-String
Write-Host
write-host "----- Groups -----"
Write-Host $GroupsResult
write-host "----- Users -----"
Write-Host $UsersResult
#-------------------------------------------------------

沒有留言:

張貼留言