我有一个脚本可以在特定子网上的约600个系统上运行。我正在收集systeminfo并检查TPM状态。我有一个.txt文件,其中包含要检查的所有Windows 10系统的名称。问题是,对于无法访问的每个系统(关闭电源等),在脚本转到下一个系统之前,超时时间很长。这可能会花费非常长的时间。有没有办法限制此超时时间?例如,如果系统在2秒钟内没有响应,它将跳至下一个。
$exportString = ""
foreach ($computersystem in Get-Content C:\Scripts\tpmmachines.txt) {
$computerinfo = Get-WmiObject -ComputerName $computersystem Win32_ComputerSystem
$computerBIOS = Get-WmiObject -ComputerName $computerSystem Win32_BIOS
$computerOS = Get-WmiObject -ComputerName $computerSystem Win32_OperatingSystem
$tpm = Get-WmiObject -Class Win32_Tpm -Namespace root\CIMV2\Security\MicrosoftTpm -ComputerName $computerSystem -Authentication PacketPrivacy |
Select-Object IsEnabled_InitialValue, ManufacturerId,
ManufacturerVersion, ManufacturerVersionInfo,
PhysicalPresenceVersionInfo, SpecVersion
"System Information for: " + $computerinfo.Name
""
"Manufacturer: " + $computerinfo.Manufacturer
"Model: " + $computerinfo.Model
"Serial Number: " + $computerBIOS.SerialNumber
"Bios Version: " + $computerBIOS.Version
"TPM OEM ID: " + $tpm.ManufacturerId
"TPM OEM Ver: " + $tpm.ManufacturerVersion
"TPM Enabled: " + $tpm.IsEnabled_InitialValue
"Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
"User logged In: " + $computerinfo.UserName
"Last Reboot: " + $computerinfo.ConvertToDateTime($computerOS.LastBootUpTime)
""
""
$exportString += "System Information for: $($computerinfo.Name)`n`n Model: $($computerinfo.Model)`n Serial Number: $($computerBIOS.SerialNumber)`n Bios Version: $($computerBIOS.Version)`n TPM OEM ID: $($tpm.ManufacturerID)`n TPM OEM Ver: $($tpm.ManufacturerVersion)`n TPM Enabled: $($tpm.IsEnabled_InitialValue)`n Operating System: $($computerOS.caption), Service Pack: $($computerOS.ServicePackMajorVersion)`n User logged In: $($computerinfo.UserName)`n Last Reboot: $($computerinfo.ConvertToDateTime($computerOS.LastBootUpTime))`n`n`n"
}
$exportString | Out-File -FilePath C:\scripts\TPM.txt
我的预期结果是加快无法访问系统的超时,并减少该脚本在Get-Content
文件中的所有系统上运行所花费的时间。对于每个超时的系统,最终超时并接收以下错误消息最多需要20-30秒:
Get-WmiObject : The RPC server is unavailable. At line:4 char:17 + ... puterinfo = Get-WmiObject -ComputerName $computersystem Win32_Compute