运行硬件资源清册脚本时出现Powershell错误
当我运行以下代码时,我在-computername-quiet-count1处收到一个错误,表示-properties操作系统存在问题| Select。完整代码如下:运行硬件资源清册脚本时出现Powershell错误,powershell,Powershell,当我运行以下代码时,我在-computername-quiet-count1处收到一个错误,表示-properties操作系统存在问题| Select。完整代码如下: $Comps = Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*' } -Properties OperatingSystem | select -ExpandProperty Name foreach ($Comp in $comps) { i
$Comps = Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*' } -Properties OperatingSystem | select -ExpandProperty Name
foreach ($Comp in $comps) {
if ((test-connection -ComputerName $Comp -Quiet -count 1 )) {
Get-WmiObject win32_processor -ComputerName $Comp | select DeviceID,Name,Manufacturer,NumberOfCores,NumberOfLogicalProcessors
}
else {
write-host " $Comp Appears offline"
}
}
更新:针对新错误进行编辑
-属性:术语'-properties'不被识别为
cmdlet、函数、脚本文件或可操作程序。检查单词的拼写
名称,或者如果包含路径,请验证路径是否正确,然后重试。
第3行字符:1
+-属性操作系统|选择
+ ~~~~~~~~~~~
+CategoryInfo:ObjectNotFound:(-properties:String)[],命令
NotFoundException
+FullyQualifiedErrorId:CommandNotFoundException
-ExpandProperty:术语'-ExpandProperty'不被识别为的名称
cmdlet、函数、脚本文件或可操作程序。检查单词的拼写
名称,或者如果包含路径,请验证路径是否正确,然后重试
再一次。
第4行字符:1
+-扩展属性名称
+ ~~~~~~~~~~~~~~~
+CategoryInfo:ObjectNotFound:(-ExpandProperty:String)[],Com
mandNotFoundException
+FullyQualifiedErrorId:CommandNotFoundException您的代码对我来说运行良好:
$Comps = Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*' } -Properties OperatingSystem | select -ExpandProperty Name
foreach ($Comp in $comps) {
if ((test-connection -ComputerName $Comp -Quiet -count 1 )) {
Get-WmiObject win32_processor -ComputerName $Comp | select SystemName,DeviceID,Name,Manufacturer,NumberOfCores,NumberOfLogicalProcessors | Export-Csv -NoTypeInformation procs.csv -Append
} else {
write-host " $Comp Appears offline"
}
}
…我偶尔会遇到拒绝访问的错误,但它对某些系统起作用。不过,您可能应该发出带有处理器信息的computername,否则您将很难区分什么硬件与什么计算机搭配。在
-count
和1
之间添加一个空格。最好在问题中包含错误消息。不要将筛选器作为脚本块编写。它应该是一个类似于-Filter“OperatingSystem-like'*Windows Server*”
的字符串。添加了新错误,您的更改仍然存在o错误。是!似乎格式化是个问题。如何将数据输出到列表中?请参阅带有以下更改的编辑:从Win32_processor添加SystemName属性,并使用-Append开关将输出传输到CSV,以便将结果聚合到CSV中。