The foreach loop just keeps print out the amount of element 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
Change this:
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)
}
To:
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)| out-null
}
Another solution is to [void]
the "offending" line:
foreach($pro in $properies)
{
[void]$ADSearch.PropertiesToLoad.add($pro)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With