11
mai
2009
2

Script PowerShell pour arrêt de VM sur VMware

Voici un script permettant l’arrêt de VM en PowerShell sur une infrastructure VMware.

Pour cette exécution vous devez utiliser le VMware Infrastructure Toolkit -> http://www.vmware.com/download/download.do?downloadGroup=VI-WT-15

 

#—————— Début Script ————

 

Add-PSsnapin VMware.VimAutomation.Core


$Name = “*”  # à changer au besoin

$Location = “*” # à changer au besoin

$WhatIf = $true  # mettre “$false” pour une exécution réelle


Connect-VIServer -Server virtualcenter  >$null


Write-Progress “Checking VM Guest Status” “Working…”

$vmGuest = Get-VM $Name -Location $Location | ? { $_.PowerState -ne “PoweredOff” } | Get-VMGuest

for ( $i = 0; $i -lt $vmGuest.Count; $i++ ) {

    Write-Progress “Shutting down VMs” “Virtual machine: $($vmGuest[$i].VmName)” `

        -percentComplete ( $i / $vmGuest.Count * 100)

    if ( $vmGuest[$i].State -eq “Running” ) {

        Shutdown-VMGuest -Guest $vmGuest[$i] -Confirm:$false -WhatIf:$WhatIf

    } else {

        Stop-VM -VM $vmGuest[$i].VmName -Confirm:$false -RunAsync -WhatIf:$WhatIf

    }

}

#—————- Fin Script ————–

ps : commande pour débloquer l’exécution dans power shell -> Set-ExecutionPolicy Unrestricted
Ecrit par admin dans : VmWare | Tags : , , ,

Propulsé par WordPress | Thème Aeros | TheBuckmaker.com WordPress Themes | Traduction WordPress tuto