Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Powershell Filter doesn't accept comma

Im try to use the Get-User command with a simple Filter.

Get-User -Filter "(Manager -eq 'Max, Mustermann')"

The problem is that i get this exception:

Cannot bind parameter ‘Filter’ to the target. Exception setting "Filter": "The value "Max, >Mustermann" could not be converted to type
Microsoft.Exchange.Data.Directory.ADObjectId.
"(Manager -eq ‘Max, Mustermann’)" at position 34."
In C:\Users\JAKO\AppData\Local\Temp\tmp_4vtu0s13.ymv\tmp_4vtu0s13.ymv.psm1:38356 Zeichen:9

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  •     $steppablePipeline.End()
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : WriteError: (:) [Get-User], ParameterBindingException
    • FullyQualifiedErrorId : >ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.GetUser

As far as I understand the Problem its because of the comma, so i tryed some workaorunds.

Get-User -Filter "(Manager -like 'Max, Mustermann')"

Here I dont get an exception but there are no Users that get returned.

Get-User -Filter "(Manager -eq 'Max"," Mustermann')"

The same as with the other workaround. No exception but no Users are Matching.
I also made sure that i have Users that would match this specift query, by using this command

Get-User -Filter | Format-List Manager

How can I write my Filter input so it matches "Max, Mustermann"?

>Solution :

From the filtering documentation for the Manager attribute:

This filter requires the distinguished name or canonical distinguished name of the manager (a mailbox or mail user). For example, Get-User -Filter "Manager -eq 'CN=Angela Gruber,CN=Users,DC=contoso,DC=com'" or Get-Mailbox -Filter "Manager -eq 'contoso.com/Users/Angela Gruber'".
To find the distinguished name of a manager, replace with the name, alias, or email address of the recipient, and run this command: Get-Recipient -Identity "<RecipientIdentity>" | Format-List Name,DistinguishedName.

So now we know why the filter isn’t working (a distinguished name is expected), and how to obtain the correct value (by using Get-Recipient):

# Fetch manager's user account object
$targetUser = Get-Recipient -Filter "SimpleDisplayName -eq 'Max, Mustermann'"

# Fetch reports 
Get-User -Filter "Manager -eq '$($targetUser.DistinguishedName)'"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading