VMware

PowerCLI trying to shutdown, snapshot, turn back on and later delete snapshots from a resource pool

So part of our Windows patching is snapshot the VM before so we can roll back if needed. Some of our VMs are large with 64GB of memory and they take forever so we just shutdown, snapshot and turn back on. We don’t have a ton so we can do it manually but if we could automate that would be ideal.


View Reddit by relegatedredditView Source

Related Articles

One Comment

  1. $name = ‘computer1′,’computer2′,’computer3’

    #if computers are domain joined, I recommend this before snapshots,
    #otherwise you have 0-30 days before your snapshot won’t have
    #domain connectivity if you restore
    Invoke-Command $vmList { Reset-ComputerMachinePassword } -ErrorAction Stop

    start-sleep -seconds 30 #give the reset password a bit of time to cook

    $vmList = Get-VM $name
    $vmList | Stop-VM

    while ($vmList.ExtensionData.Runtime.PowerState -match ‘poweredon’){
    $vmList.ExtensionData.UpdateViewData(‘runtime.powerstate’)
    Write-Verbose -Verbose ‘waiting for vm shutdown’
    Start-Sleep -seconds 2
    }

    $vmList.Where({$PSItem.ExtensionData.Snapshot}).name -replace ‘$’,’ has snapshot’ | Write-Warning

    $vmList.where({ -not $PSItem.ExtensionData.Snapshot }) |
    New-Snapshot -Name ‘snapshot name’ -Description ‘snapshot description’

    $vmList | Start-VM

    Haven’t tested this, but this is the general process I would follow.

Leave a Reply

Your email address will not be published. Required fields are marked *

Close