使用下面的代碼我試圖找到服務器在我們的SQL數據庫(手動輸入,很容易出錯)和vCenter中與電源狀態不匹配。雖然我的工作效果並不好,但是從-And $VM.PowerState -like "PoweredOn"
開始,它一次獲得所有服務器(大約500個)的狀態,而不是一個服務器,導致語句始終失敗。在ForEach中迭代多個變量
# $VM = List of Virtual Machines, properties Name and PowerState
# $ServerList = List of Servers, properties Name and Status.
foreach ($serverEntry in $ServerList) {
if ($VM.Name -contains $serverEntry.Name -And $VM.PowerState -like "PoweredOn" -And $serverEntry.Status -like "In Use") {
Stuff will happen
} else {
Some other stuff
}
}
我嘗試了嵌套循環,但不能得到那個工作,因爲服務器不在同一順序列出我不能用一個簡單的計數器($i
)。
我該如何解決這個問題?
幾乎但不完全。 「使用中」與「PoweredOn」和「PoweredOff」相匹配。只有當它與「未使用」狀態匹配並且轉到「其他」部分時,狀態纔是其他使用狀態(例如「已刪除」或「等待刪除」 – Notumlord
我對此表示懷疑請提供證據 –
有一刻..... – Notumlord