Foreach 与 Foreach-Object 的区别

时间:2022-10-19 05:28:34
下面两个实例可以看出:
 
Get-ADGroupMember -Identity "CN=gAPCHN-HGZ-IE10-Users,OU=Groups,OU=Hangzhou - China,OU=TCS - China,OU=TCS - China,DC=apac,DC=TCS,DC=com" | select -Property SamAccountName | ForEach-Object {
    Get-ADUser -Identity $PSItem.SamAccountName -Properties * | select DisplayName
}
 
$SANs = Get-ADGroupMember -Identity "CN=gAPCHN-HGZ-IE10-Users,OU=Groups,OU=Hangzhou - China,OU=TCS - China,OU=TCS - China,DC=apac,DC=TCS,DC=com" | select -Property SamAccountName
Foreach ($PSItem in $SANs) {
    Get-ADUser -Identity $PSItem.SamAccountName -Properties * | select DisplayName
}