# Quering AD to get Windows Server List

**URL:** <https://forums.powershell.org/t/quering-ad-to-get-windows-server-list/7471>\
**Category:** PowerShell Help\
**Created:** [November 4, 2016, 12:54pm UTC](https://forums.powershell.org/t/quering-ad-to-get-windows-server-list/7471 "2016-11-04T12:54:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![helderguzman](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/helderguzman/32/401_2.png) [@helderguzman](https://forums.powershell.org/u/helderguzman)\
**Post date:** [November 4, 2016, 12:54pm UTC](https://forums.powershell.org/t/quering-ad-to-get-windows-server-list/7471/1 "2016-11-04T12:54:08Z")

</div>

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 …
- 

```auto
  + 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?

---

<div class="post-metadata">

**Author:** ![aduzsardi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/aduzsardi/32/112_2.png) [@aduzsardi](https://forums.powershell.org/u/aduzsardi)\
**Post date:** [November 4, 2016, 1:58pm UTC](https://forums.powershell.org/t/quering-ad-to-get-windows-server-list/7471/2 "2016-11-04T13:58:33Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![skalizar](https://avatars.discourse-cdn.com/v4/letter/s/ecc23a/32.png) [@skalizar](https://forums.powershell.org/u/skalizar)\
**Post date:** [November 4, 2016, 2:26pm UTC](https://forums.powershell.org/t/quering-ad-to-get-windows-server-list/7471/3 "2016-11-04T14:26:54Z")

</div>

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
                                              ^
```

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [November 6, 2016, 4:09am UTC](https://forums.powershell.org/t/quering-ad-to-get-windows-server-list/7471/4 "2016-11-06T04:09:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 6, 2016, 5:34am UTC](https://forums.powershell.org/t/quering-ad-to-get-windows-server-list/7471/5 "2016-11-06T05:34:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/quering-ad-to-get-windows-server-list/7471/6 "2024-05-16T20:40:02Z")

</div>


