我正在尝试整理组。我有以下示例。这些在本地组中是本地的,在本地组中是全局的。有时有a组是b组成员,b是c组成员。我想要得到的是最后一个小组及其成员。
这是脚本之外的代码片段,但确实可以正常工作。
$test1 = Get-ADGroup -Filter {Name -eq `$id -and GroupScope -eq "DomainLocal"}
$ADGroup = Get-ADGroup $Id -Properties member | Select-Object -ExpandProperty member
if($test1 -ne $false)
{
$GrName = (Get-ADGroup $id -Properties member | Select-Object -ExpandProperty member | %{Get-ADGroup $_}).name
foreach($group in $GrName)
{
$test2 = Get-ADGroup -Filter {Name -eq $group -and GroupScope -eq "DomainLocal"}
$ADGroup = Get-ADGroup $Id -Properties member | Select-Object -ExpandProperty member
if($test2 -eq $false)
{
$GrName = (Get-ADGroup $id -Properties member | Select-Object -ExpandProperty member | %{Get-ADGroup $_}).name
foreach($group2 in $GrName)
{
$ADGroup = Get-ADGroup $group2 -Properties member | Select-Object -ExpandProperty member
Write-Host "`n" | Out-File $log -append
Write-Output "Mitglieder von $group2 : `n" | Out-File $log -append
$result = $group2.length + 17
$test = "-"*$result
$test | Out-File $Log -Append
foreach ($Object in $ADGroup)
{
$GetName = Get-ADUser -filter * -SearchBase "$Object"
if($GetName -ne $null)
{
$Name = $GetName.SamaccountName
Write-Output $name | Out-File $log -append
}
}
}
if($test2 -ne $false)
{
Write-Host "`n" | Out-File $log -append
Write-Output "Mitglieder von $Id : `n" | Out-File $log -append
$result = $id.length + 17
$test = "-"*$result
$test | Out-File $Log -Append
foreach ($Object in $ADGroup)
{
$GetName = Get-ADUser -filter * -SearchBase "$Object"
if($GetName -ne $null)
{
$Name = $GetName.SamaccountName
Write-Output $name | Out-File $log -append
}
}
}
}
我得到的是
a1组成员:空
a2组成员:空
a3组成员:空
因为它们不是列表的最后一组。
我试图获得什么?
c1组成员:成员1,成员2