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

Cannot use variable as a get-adcomputer filter parameter

$
0
0

I’ll omit the bulk of my script and just focus on this piece that is not working. Maybe there is an easier way to accomplish this.


$filter = "-filter 'name -like" + " <code>&quot;$computername</code>"'"
Get-ADComputer $filter | select -ExpandProperty name

Error: Get-ADComputer : Cannot find an object with identity: ‘-filter ‘name -like “someHostName”” under: ‘DC=xx,DC=xxx,DC=org’.

However, I can echo $filter, take it’s exact output, append it to get-adcomputer and it works.

I’m confused.


Viewing all articles
Browse latest Browse all 13067

Trending Articles