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

最佳答案

更改此:

foreach($pro in $properies)
{
    $ADSearch.PropertiesToLoad.add($pro)
}

至:
foreach($pro in $properies)
{
    $ADSearch.PropertiesToLoad.add($pro)| out-null
}

08-07 17:56