WMIクエリを使用してWindowsサーバから数値Multipathを見つける小さなスクリプトを作成しました。それは問題なく直接接続できるサーバーでうまく動作します。しかし、1つのサーバがping可能でWMIスクリプトを経由することができない場合は、エラーを返すのに時間がかかります(たとえば、Linuxサーバのホスト名がservers.txtリストにある場合など)。より速い方法で..?PowershellからWMIクエリを実行する方法はありますか?
$Servers = Get-Content .\Servers.txt
$ErrorActionPreference = ‘SilentlyContinue’
FOREACH ($Server in $Servers) {
Write-Host $Server -nonewline
if (test-connection -computername $Server -Count 1 -quiet) {
$Name = $null
$NoPath =$null
$MPIODisks =$null
$MPIODisks = Get-WmiObject -Namespace root\wmi -Class mpio_disk_info -ComputerName "$Server" |Select-Object "DriveInfo"
if ($MPIODisks -eq $Null) {
write-host "`t - Unable to connect" -fore "RED"
} else {
write-host ""
write-host "Drive Name `tNo.Path" -fore "yellow"
Foreach ($Disk in $MPIODisks) {
$mpiodrives = $disk.DriveInfo
foreach ($Drive in $mpiodrives) {
$Name = $Drive.Name
$NoPath = $Drive.Numberpaths
If ($NoPath -lt 4) {
Write-Host $Name `t -nonewline
write-host $NoPath -fore "Red"
} else {
Write-Host $Name `t -nonewline
write-host $NoPath -fore "Green"
}
}
}
}
write-host ""
} else {
write-host "`t- Unknown Host" -fore "Red"
write-host ""
}
}
使用しているのPowerShellのバージョンを? –
新しいバージョンでは、 'Get-CimInstance -OperationTimeoutSec' –