I’m trying to write a simple powershell script.
Get-ADuser -Filter {GivenName -eq $GivenName $hateList} -SearchBase $Container -Properties displayName,telephoneNumber,department|ForEach-Object {"FullName`t: $($_.displayName)`r`nPhone`t`t: $($_.telephoneNumber)`r`nDepartment`t: $($_.department)`r`n"}
The error what I got:
Get-ADUser : Error parsing query: ‘GivenName -eq $GivenName $hateList’ Error Message: ‘syntax error’ at position: ’26’.
So the problem is that the variables aren’t substituted with their values. What do I do wrong?
You Filter parameter is not right. If you want to have GivenName be equal to $GivenName you should do it like this:
If you want it to be equal to $GivenName or $hateList, whatever it is, you should try something like:
Check this link for more filter:
http://technet.microsoft.com/en-us/library/ee617241.aspx
You can first get list of users with filter like this:
And the do some post processing: