AD Cmdlet -Filter Faffing

I'm aware that I write for an international audience and I try to use international English in my posts.

 

When I use traditional or colloquial English I usually have a good reason for doing so. Today's reason is because I like the alliteration that 'Filter Faffing' provides.

 

faffing - the act of making a task more awkward or time-consuming than it ought to be...  

 

For those of you who've worked with the Active Directory PowerShell module over the years, you'll know that it has its idiosyncrasies.

 

Arriving at the correct syntax for the -Filter parameter can sometimes be fun. If you check out the help entry for the -Filter option the returned information can be a little impenetrable because of the use of Backus-Naur notation.

 

 
man Get-ADComputer -Parameter filter

 

 

 

Someone was on their fourth coffee when writing documentation that day! In fact, their finger prints are over a lot of the module documentation...

 

 
get-help Backus

 

 

Sifting through the Backus-Naur notation, you soon realise that the -Filter parameter should accept something like standard PowerShell syntax… sometimes, though, the syntax is nothing like what you'd expect.

 

Consider this…

 

 
$param = "unn"
Get-Service | ? {$_.status -like "*$param*"} | Select-Object -First 5

 

 

All good, so far. Now, consider this…

 

 
$paramm = "arr"
Get-Aduser -Filter {SamAccountName -like "*$paramm*"}

 

 

Odd. And, now consider this…

 

 
$paramm = "arr"
Get-Aduser -Filter "SamAccountName -like '*$Paramm'"

 

 

"Curiouser and curiouser!", cried PoSh Chap (he was so much surprised, that for the moment he quite forgot how to speak traditional English), "Definitely, one to look out for!"