나는 자동화하기를 바라고있는 꽤 큰 감사 프로젝트를 가지고 있습니다.powershell 그룹의 구성원을 재귀 적으로 검색합니다.
그룹의 일부인 모든 사용자 이름, SamAccountName, Title 및 Department를 얻어야합니다. 문제는 그룹에 그룹이 있고 그룹 내에 그룹이 있다는 것입니다. 또 다른 문제점은 모든 그룹의 약 99 %가 표시 이름 (별칭 SamAccountName)에 별표가 있음을 나타냅니다.
여기에 현재 코드가 있습니다. 이름에 별표가있는 그룹을 수신 할 때까지 작동합니다 (따라서 .Replace ("*", "") 부분 ...). 아무도 아이디어가 없습니다. Bill_Stewart 말했듯이?
function Get-NestedGroupMember {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Group
)
$broke = @();
## Find all members in the group specified
$members = Get-ADGroupMember -Identity $Group
foreach ($member in $members){
## If any member in that group is another group just call this function again
if ($member.objectClass -eq 'group'){
$memberGroup = $($member.Name).Replace("*", "")
try{
Get-NestedGroupMember -Group "$($memberGroup)"
}catch{
$broke += "$($memberGroup)`n"
}
}else{
## otherwise, just output the non-group object (probably a user account)
$member.Name
}
}
Write-Host "`nThe following groups could not be found automatically.`n`n$($broke)"
}
$getGroup = Read-Host -Prompt "Group name"
Get-NestedGroupMember $getGroup
그리고 '-Recursive' 매개 변수를 사용하고 있지 않으므로 ... –