嘿我正在尝试运行一个脚本来让每个计算机都在我的工作域中,但是我在过滤掉我们的服务器时遇到了问题。在这个例子中,我正在尝试使用操作系统版本10.0(10240)和版本10.0(10586)的计算机。
这就是我所拥有的。
$OSVersion = "10.0 (10240)", "10.0 (10586)"
Get-ADComputer -Filter ($_.OperatingSystem -eq $OSVersion) -Property * | Select-object Name,OperatingSystem,OperatingSystemVersion | Export-Csv 'C:\SomePath.csv'
但我回来了
Get-ADComputer : Error parsing query: 'False' Error Message: 'syntax error' at position: '1'.
At C:scriptPath:3 char:1
+ Get-ADComputer -Filter ($_.OperatingSystem -eq $OSVersion) -Property ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADComputer], ADFilterParsingException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
任何人都知道解决方案吗?
答案 0 :(得分:1)
或者就这样做......
Clear-Host;'6.3 (9600)','10.0 (14393)' | %{Get-ADComputer -Filter * -Properties OperatingSystem,OperatingSystemVersion | Where OperatingSystemVersion -EQ $_ | Select Name,OperatingSystem,OperatingSystemVersion}
Results ---
Name OperatingSystem OperatingSystemVersion
---- --------------- ----------------------
DC01 Windows Server 2012 R2 Standard 6.3 (9600)
...
...
...
IIS01 Windows Server 2016 Datacenter 10.0 (14393)
我假设您的尝试基于您的帖子。
答案 1 :(得分:1)
使用过滤器和foreach
$OSVersion = @("10.0 (10240)", "10.0 (10586)")
Foreach($version in $OSVersion){
Get-ADComputer -Filter {OperatingSystem -match $Version} -Property OperatingSystem,OperatingSystemVersion | Select-object Name,OperatingSystem,OperatingSystemVersion | Export-Csv 'C:\SomePath.csv'
}