私はかなり大きな監査プロジェクトを手に入れました。powershellはグループのメンバーを再帰的に検索します
グループのメンバーであるすべてのユーザーの名前、SamAccountName、Title、Departmentを取得する必要があります。問題は、グループにグループがあり、グループ内にグループがあることです。別の問題は、すべてのグループの約99%がアスタリスクを表示名(NOT 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'パラメータを使用していません... –