Powershell列出AD组中子组中的成员

时间:2017-08-01 16:16:36

标签: powershell

我是PowerShell的新手,还在学习。我想要做的是搜索AD组中所有成员的列表,以及该原始组中是否有一个组来显示这些成员等等。例如:

服务器:" LocalZoo"

  • 本地管理员
    • 中央/主要管理员
    • 东/冷管理员
    • West / Hot Admin
    • 东/鲍勃
    • 东/艾米丽
    • 西/约翰
    • 中部/威尔

子组:中央/主要管理员

  • 成员:
    • 中部/威尔
    • 中部/尼克
    • 中部/玫瑰

子组:东/冷管理员

  • 会员:

    • 东/鲍勃
    • East / Jess
    • 东/动物园动物
  • 子组: East / Zoo Animal

    • 成员:
    • 东/北极熊
    • 东/ SEEL

子组: West / Hot Admin

  • 成员:
    • 西/瑞克
    • 西/莫蒂

到目前为止,我可以使用此代码获取第一组中的成员列表,但不确定如何进一步。



function get-localadmins{
  [cmdletbinding()]
  Param(
  [string]$computerName
  )
  $group = get-wmiobject win32_group -ComputerName $computerName -Filter "LocalAccount=True AND SID='S-1-5-32-544'"
  $query = "GroupComponent = `"Win32_Group.Domain='$($group.domain)'`,Name='$($group.name)'`""
  $list = Get-WmiObject win32_groupuser -ComputerName $computerName -Filter $query
  $list | %{$_.PartComponent} | % {$_.substring($_.lastindexof("Domain=") + 7).replace("`",Name=`"","\")}
}

$Server = Read-Host "Server Name"
get-localadmins $Server




0 个答案:

没有答案
相关问题