最近我发现自己不得不经常关闭我的家庭实验室,因为天气比预期的要好,温度急剧上升。
为了加快关闭所有虚拟机(目前为 68 个)的过程,我决定敲出一个非常简单的 PowerCLI 脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| # Variables
$esxi = "esxi.mdb-lab.com"
$credential = Get-Credential
Connect-VIServer $esxi -Credential $credential
Get-VM | where {$_.Powerstate -eq "PoweredOn"} | Shutdown-VMGuest -Confirm:$false
Start-Sleep -s 600
Stop-VMHost -Confirm:$false -Force:$true
Disconnect-VIserver $esxi -Confirm:$false
|