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>"$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.