Author Posts

November 4, 2016 at 6:24 pm


I'm doing a basic query to find out the all the Server in one domain. I run the following line

Get-ADComputer -Filter {OperatingSystem -Like “Windows Server*”} -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap -Auto

and I'm getting this error

Get-ADComputer : Error parsing query: 'OperatingSystem -Like “Windows Server*”' Error Message: 'syntax error' at position: '23'.
At C:\Users\hguzman\Desktop\PSScripts\servers.ps1:10 char:1
+ Get-ADComputer -Filter {OperatingSystem -Like “Windows Server*”} -Property * | F ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADComputer], ADFilterParsingException
+ FullyQualifiedErrorId : Error parsing query: 'OperatingSystem -Like “Windows Server*”' Error Message: 'syntax error' at position: '23'.,Microsoft.Act

why I get this error?

November 4, 2016 at 7:28 pm

looks like powershell doesn't like your quotes in the filter , try this

Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"} -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap -Auto

November 4, 2016 at 7:56 pm

There is something wrong with the open quotes. I can't tell visually, but if I replace it, it works.

Get-ADComputer -Filter {OperatingSystem -Like “Windows Server*”} -Property * | Format-Table

November 6, 2016 at 9:39 am

This works fine
Get-ADComputer -Filter {OperatingSystem -like "Windows Server*"} -Properties *

Looks like its the quotes rather than the syntax

Single quotes work as well

November 6, 2016 at 11:04 am

That usually happens when you copy code from a website or a word document. Just replace the curved quotation marks with the normal straight ones and I assume it will work as expected.