桌面場景切換用到:(上課、閱卷場景切換)ide
批量關機腳本1:spa
$vc = '192.168.0.8'虛擬機
Connect-VIServer -Server $vc -usrname"administrator@vsphere.local" -Password "1qaz!QAZ"it
$vm2=Get-View -ViewType "VirtualMachine" -Filter@{"Name" = "yj*"}class
foreach ($vm in $vm2){foreach
if($vm.RuntimePowerState -eq "PoweredOn"){im
$vm.PowerOffVM()}腳本
}margin
批量關機腳本2:word
$vc = '192.168.0.8' #VCenter IP
?
Connect-VIServer -Server $vc -username"administrator@vsphere.local" -Password "1qaz!QAZ"
$VMs = Get-ResourcePool 上課6-1 |Get-VM "shangke*"
foreach( $vm in $VMs ) { Shutdown-VMGuest$vm -Confirm:$false}
這個腳本若是虛擬機原來是關機狀態,執行該腳本會有紅色警告提示,忽略便可。
批量開機腳本:
$vc = '192.168.0.8'
Connect-VIServer -Server $vc-usrname "administrator@vsphere.local" -Password "1qaz!QAZ"
$vm2=Get-View -ViewType"VirtualMachine" -Filter @{"Name" = "yj*"}
foreach ($vm in $vm2){
if($vm.Runtime PowerState -ne "PoweredOn")
{
$vm.PowerOffVM($vm.Runtime.Host)
}
}
備註:yj*表示桌面虛擬機名字以yj開頭。