# Exchange PowerShell - Evaluating expressions in the Filter parameter


Recently I needed to get a bunch of groups from Exchange by their **ExternalDirectoryObjectId** property. There are many ways to do this and one of the easiest would be to just get the Name (or other unique identifier) by looking up the group in AAD via MSOL PS. However, you can use the -Filter parameter for **Get-DistributionGroup** cmdlet and specify the id:

```powershell
Get-DistributionGroup -Filter { ExternalDirectoryObjectId -eq $group.ExternalDirectoryObjectId }
```

<!--truncate-->

However, when you try this you may get an error saying that it's invalid syntax:

```log
Cannot bind parameter 'Filter' to the target. Exception setting "Filter": "Invalid filter syntax. For a description of
the filter parameter syntax see the command help.
"ExternalDirectoryObjectId -eq $group.ExternalDirectoryObjectId" at position 31."
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706035545420/1a8733c5-5c4f-4658-9981-8c68354e51a5.png)

After a bit of searching I came across [this](https://community.spiceworks.com/topic/1200787-variables-give-unexpected-results-in-exchange-script) forum post.

Apparently PowerShell won't evaluate expressions in the filter script block. You can assign the **$group.ExternalDirectoryObjectId** to it's own variable before the filter but for me that didn't work either. What did work was using quotes instead of curly brackets, as below:

```powershell
Get-DistributionGroup -Filter "ExternalDirectoryObjectId -eq '$($group.ExternalDirectoryObjectId)'"
```

This finally returns the group by id!

