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
Change this:
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)
}
To:
foreach($pro in $properies)
{
$ADSearch.PropertiesToLoad.add($pro)| out-null
}