I tried various things with filter but it will only return errors like this or returns null. Any ideas? I can’t seem to figure it out. I tried tracing and using ISE to debug, but I can’t understand why it won’t return anything…
The filter option is a bit wacky. The filter uses PowerShell Expression Language. If you look at the help, you see that the filter parameter takes in a string:
PS C:\> Get-Help Get-ADUser -Parameter Filter
-Filter
Required? true
Position? Named
Accept pipeline input? false
Parameter set name Filter
Aliases None
Dynamic? true
So anything you will pass to the filter will be taken in as a string. To get the subexpression to work, so expanding the variable and return it as a string to the filter, you put these within single quotes.