Quering AD to get Windows Server List

This topic contains 4 replies, has 5 voices, and was last updated by Profile photo of Olaf Soyk Olaf Soyk 4 weeks ago.

  • Author
    Posts
  • #56927
    Profile photo of Helder Guzman
    Helder Guzman
    Participant

    Hi

    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
    iveDirectory.Management.Commands.GetADComputer

    why I get this error?

  • #56938
    Profile photo of Alexandru
    Alexandru
    Participant

    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
    Profile photo of Ron
    Ron
    Participant

    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
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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
      Profile photo of Olaf Soyk
      Olaf Soyk
      Participant

      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.