【发布时间】:2019-01-06 06:09:57
【问题描述】:
我一直在使用 PowerShell 查询域并过滤域内域客户端和服务器上的结果以用于报告目的。
我有一个有效的 PowerShell 命令,它利用“Get-ADComputer”模块列出域的所有成员,并在可以导出到 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)
我正在尝试使用此命令的 2 个附加版本,它们会进一步过滤上述结果,并且仅显示包含“OperatingSystem”的 Get-ADComputer Properties 字段且包含“Windows Server”字样的条目。此 PowerShell 命令引发了我不确定原因的语法错误?
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
命令的第二次迭代与第一次相反;它应该排除所有包含“服务器”一词的条目,但是此命令也不起作用并引发以下语法错误?
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
谢谢。
【问题讨论】:
标签: powershell