reboot multiple vms on vsphere

여러대 vm을 동시에 리부팅하기

<reboot-vms.ps1>

Connect-VIServer -Server vCenter -User [아이디] -Password [패스워드]
$vms=Get-VM | Where-Object {$_.powerstate -eq 'PoweredOn' -and $_.name -like '[VM명]*'}
$vms | select Name | export-csv c:\genie\genie-reboot.csv -NoTypeInformation
$vms | Restart-VMGuest
Disconnect-VIServer -Confirm:$false

 

위 스크립트 작성후 윈도우 작업 스케쥴러에 다음과 같이 걸어줌

프로그램 : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

인수추가 : -psc “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1” “& ‘c:\genie\reboot-vms.ps1′”

function main([string]$vmname=$args[0]) {
Connect-VIServer -Server vCenter -User  -Password

$vms=Get-VM | Where-Object {$_.powerstate -eq ‘PoweredOn’ -and $_.name -like “$vmname*”}
$vms | select Name | export-csv “c:\genie\$vmname.csv” -NoTypeInformation
$vms | Restart-VMGuest
Disconnect-VIServer -Confirm:$false
}
main