Trying to Get-Aduser based on description. I have a csv with a list of serial numbers. These are added to the description field of Ad users. When I run my code nothing returns.
CSV:
Description
5CD50801ZC
98VGJ42
J8TFJ42
6NVFJ42
7PQFJ42
1GTFJ42
Two things here: One, the -Like operator requires some wildcards, if you’re planning to look for a string that contains something else. Also, you need to be looking at $line.Description, rather than just $line. Try this:
I’ve changed your -Filter argument from a script block literal to a double-quoted string, based on past experience with the AD cmdlets where sometimes the script block syntax doesn’t work the way you expect it to.
That’s a sub-expression operator, and is what you use in strings when you want to expand something more complex than just a simple variable name. Otherwise, $line would get expanded, and the text “.Description” would become a literal part of the string, which is not what we want.