Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Cannot use variable as a get-adcomputer filter parameter

$
0
0

The post is a bit malformed with HTML stuff, but here’s how it should look:

Get-ADComputer -Filter "Name -like '$computername'"

You can sometimes get away with using curly braces and script block syntax (and this is all over the examples), but the -Filter parameter actually expects a string, and this is the most consistent way of getting it to work. In your case, though, the curly brace syntax would probably also work fine:

Get-ADComputer -Filter { Name -like $computername }

It’s mostly when you need to filter based on object properties (such as Name -like $computer.Name ) where the script block example syntax starts to fall apart.


Viewing all articles
Browse latest Browse all 13067

Trending Articles