Reputation: 845
The foreach loop just keeps print out the number of elements in it as the following code. I want to stop it from printing it out.
$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)
}
At the moment it gives:
0
1
2
3
4
5
6
Upvotes: 5
Views: 1368
Reputation: 10107
Another solution is to [void]
the "offending" line:
foreach($pro in $properies)
{
[void]$ADSearch.PropertiesToLoad.add($pro)
}
Upvotes: 4
Reputation: 9133
Change this:
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)
}
To:
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)| out-null
}
Upvotes: 5