foreach循环只是按照以下代码打印出元素的数量。我想阻止它打印出来。
$ADSearch = New-Object System.DirectoryServices.DirectorySearcher
$ADSearch.SearchRoot ="LDAP://$Domain"
$ADSearch.SearchScope = "subtree"
$ADSearch.PageSize = 100
$ADSearch.Filter = "(objectClass=$objectClass)"
$properies =@("distinguishedName",
"sAMAccountName",
"mail",
"lastLogonTimeStamp",
"pwdLastSet",
"accountExpires",
"userAccountControl")
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)
}
目前它给出了:
0
1
2
3
4
5
6
答案 0 :(得分:5)
改变这个:
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)
}
致:
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)| out-null
}
答案 1 :(得分:3)
另一个解决方案是[void]
“违规”行:
foreach($pro in $properies)
{
[void]$ADSearch.PropertiesToLoad.add($pro)
}