Get-ADuser : The search filter cannot be recognized"
error. It returns the following from for the value sometime (mail=user1@mail.com)(mail=user2@mail.com)(mail=user3@mail.com) and this is not even the accounts in my CSV file. it is getting them raw from the -Searchbase I am using. Anyone have an idea where I am going wrong on my syntax? Help appreciated, thanks in advance.
#$LdapFilter = '(|'
#$LdapFilter = '('
$file = 'C:\t6\Users_Email.csv'
Import-Csv $file | ForEach-Object {
$LdapFilter += "(mail=$($_.mail1))"
}
#$LdapFilter += ')'
#write-host $ldapFilter
Get-ADuser -LdapFilter $ldapFilter -Properties Name,employeeID,mail,mailNickName,employeeID | Foreach-Object{
Get-ADuser -Filter * -Server "dc01.mydomain.com" -SearchBase {"ou=users,ou=USwherever,.dc=usamer,dc=company,dc=com"} -Properties Name,employeeID,mail,mailNickName,employeeID | Select name,employeeID,mailNickName | Export-CSV -Path "C:\t6\Employee_Info.csv"
-NoTypeInformation -Append