2 つのコード ブロックがあります。
$allUsers = Get-ADUser -Filter *
foreach($_ in $allUsers.Name){
Write-Host "User $_ is member of the following groups:" -for Yellow
Get-ADPrincipalGroupMembership -Identity $_ | select Name,objectClass,Groupscope,Groupcategory | sort Name | Format-Table
}
User Administrator is member of the following groups:
Name objectClass Groupscope Groupcategory
---- ----------- ---------- -------------
Administrators group DomainLocal Security
Distributed COM U... group DomainLocal Security
Domain Admins group Global Security
Domain Users group Global Security
Enterprise Admins group Universal Security
Group Policy Crea... group Global Security
HelpLibraryUpdaters group DomainLocal Security
Schema Admins group Universal Security
User Guest is member of the following groups:
Name objectClass Groupscope Groupcategory
---- ----------- ---------- -------------
Domain Guests group Global Security
Guests group DomainLocal Security
他のバージョンは次のようになります。
$allUsers = Get-ADUser -Filter *
foreach($_ in $allUsers.Name){
Write-Host "User $_ is member of the following groups:"
Get-ADPrincipalGroupMembership -Identity $_ | select Name,objectClass,Groupscope,Groupcategory | sort Name
}
User Administrator is member of the following groups:
Name objectClass Groupscope Groupcategory
---- ----------- ---------- -------------
Administrators group DomainLocal Security
Distributed COM U... group DomainLocal Security
Domain Admins group Global Security
Domain Users group Global Security
Enterprise Admins group Universal Security
Group Policy Crea... group Global Security
HelpLibraryUpdaters group DomainLocal Security
Schema Admins group Universal Security
User Guest is member of the following groups:
Domain Guests group Global Security
Guests group DomainLocal Security
私の意見では、後者の方が読みやすいです。私の質問はこれです。コードの最初のブロックに各ユーザーのヘッダーが表示されるのはなぜですか? 私の見方では、select-object は $allUsers.Name のすべてのユーザーに対して呼び出されるため、後者のヘッダーでも毎回ヘッダーを表示する必要がありますか?