Quering AD to get Windows Server List

This topic contains 4 replies, has 5 voices, and was last updated by  Olaf Soyk 1 year, 7 months ago.

  • Author
  • #56927

    Helder Guzman


    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?

  • #56938


    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
  • #56947


    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
  • #56995

    Richard Siddaway

    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

    • #56998

      Olaf Soyk

      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.

You must be logged in to reply to this topic.