É Necessário que esteja instalado o vSphere PowerCLI na máquina a qual será executado o script.


Crie um arquivo chamado Restart-VMs.ps1 na pasta C:\Scripts\ e insira o conteúdo a seguir, posteriormente salve e feche o arquivo.

 

####################################################################
#
# Restart-VMs.ps1
# 
# -vCenter vCenter Server or Servers to connect to. 
#  Example -vCenter "vc01","vc02"
# -vmName the VM or VMs to restart. 
#  Example -vmName "VM1" or -vmName "VM1","VM2"
#
# Example:
#.\Restart-VMs.ps1 -vCenter vc01.ict-freak.local -vmName "VM1","VM2"
#
# Version 1.0 May 2010 Arne Fokkema www.ict-freak.nl @afokkema
#
#####################################################################


param(
    [parameter(Mandatory = $true)]
    [string[]]$vCenter,
    [parameter(Mandatory = $true)]
    [string[]]$vmName
)

$VIServer = Connect-VIServer $vCenter
If ($VIServer.IsConnected -ne $true){
    Write-Host "error connecting to $vCenter" -ForegroundColor Red
    exit
}

foreach($vm in $vmName){
        Write-Host "Going to restart $vm"
        Restart-VMGuest -VM (Get-VM $vm) -Confirm:$false
	Start-Sleep -s 30
}

Disconnect-VIServer -Confirm:$false

 


Execute a linha de comando no PowerShell, alterando os valores dos parâmetros "-vmName" para os nomes das máquinas virtuais que deseja reiniciar e "-vCenter" para o nome do servidor do vCenter Server.


 

 

-PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" " &  "C:\Scripts\Restart-VMs.ps1" -vCenter vcenterd.dominio.local -vmName "machine-01","macinhe-02"