Foreach 与 Foreach-Object 的区别

下面两个实例可以看出:
 
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
}

你可能感兴趣的:(foreach)