I've been utilising PowerShell to query a domain and filter results on domain clients and servers within the domain for reporting purposes.
I've got a working PowerShell command that utilises the "Get-ADComputer" module to list all members of the domain and display there OS and OS properties in a table which can be exported to csv.
PS C:\Users\Account.Domain> Get-ADComputer -Filter * -Property * | Format-Table Name,OperatingSystem,OperatingSystemService
Pack,OperatingSystemVersion -Wrap –Auto
Name OperatingSystem OperatingSystemServicePack OperatingSystemVersion
---- --------------- -------------------------- ----------------------
SRV-DC02 Windows Server 2012 R2 Datacenter 6.3 (9600)
SRV-DC01 Windows Server 2012 R2 Datacenter 6.3 (9600)
SRV-FTP01 Windows Server 2012 R2 Datacenter 6.3 (9600)
SRV241 Windows Server 2008 R2 Standard Service Pack 1 6.1 (7601)
Computer01 Windows 7 Professional Service Pack 1 6.1 (7601)
Computer02 Windows 8.1 Pro 6.3 (9600)
I'm trying to utilise 2 additional versions of this command which filter out the above results further and only display entries which include the Get-ADComputer Properties field of 'OperatingSystem' that include the words "Windows Server". This PowerShell command is throwing a syntax error which I'm not sure of the cause?
PS C:\Users\Account.Domain> Get-ADComputer -Filter {OperatingSystem -Like “Windows *Server*”} -Property * | Format-Table Na
me,OperatingSystem,OperatingSystemServicePack -Wrap –Auto
Get-ADComputer : Error parsing query: 'OperatingSystem -Like “Windows *Server*”' Error Message: 'syntax error' at
position: '23'.
At line:1 char:1
+ Get-ADComputer -Filter {OperatingSystem -Like “Windows *Server*”} -Property * | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADComputer], ADFilterParsingException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Micr
osoft.ActiveDirectory.Management.Commands.GetADComputer
The second iteration of the command is the reverse of the first; it should exclude all entries which contain the word "server" however this command is also not working and throws the below syntax error?
PS C:\Users\Account.Domain> Get-ADComputer -Filter {OperatingSystem -NotLike “*server*”} -Property * | Format-Table Name,Op
eratingSystem,OperatingSystemServicePack -Wrap -Auto
Get-ADComputer : Error parsing query: 'OperatingSystem -NotLike “*server*”' Error Message: 'syntax error' at position:
'26'.
At line:1 char:1
+ Get-ADComputer -Filter {OperatingSystem -NotLike “*server*”} -Property * | Forma ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADComputer], ADFilterParsingException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Micr
osoft.ActiveDirectory.Management.Commands.GetADComputer
Thanks.