VMware Cloud Community
jssidhu71
Contributor
Contributor
Jump to solution

Using PowerCLI to take snapshots and then removing snapshots

Hi - Wonder if someone has a script to do the following:

Scenerio:

I have 400 Virtual Desktops within a cluster, i need to create a snapshot at the beginning of the week for 100 VMs, after 2 weeks, the snapshots for these 100 VMS will be removed reverting back to the original image.

Can this be done..? if so, can anyone assist please.

Thanks

Reply
0 Kudos
43 Replies
LucD
Leadership
Leadership
Jump to solution

Do you mean that there are no snapshots on some VMs ?

With New-Snapshot, you are actually taking a snapshot of the VM.

Are you getting the hostname of the VM as an IP address instead of a FQDN ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
orgazi
Contributor
Contributor
Jump to solution

Do you mean that there are no snapshots on some VMs ?

With New-Snapshot, you are actually taking a snapshot of the VM.

I want to take snaphot of vms,whose fqdns/ips written in a cvs.

Are you getting the hostname of the VM as an IP address instead of a FQDN ?

We have successfully take snapshot of vms with fqdn-cvs,so how would the script change for ips-filled cvs.I simply changed two parts (showed below),but did cannot read csv file.



$vmTab = @{}

# Set up hash table: key = FQDN

Get-Datacenter "TTNET" | Get-VM | %{

    $vmTab.Add($_.Guest.IPAddress,$_)

}

# Loop through CSV, lookup VM on FQDN

Import-Csv C:\vm2.csv -UseCulture | %{

        New-Snapshot -VM ($vmTab[$_.ip_adress].Name) -Name "Update"

}

Disconnect-VIServer -Confirm:$false

Reply
0 Kudos
BigR
Contributor
Contributor
Jump to solution

would this work if I wanted to consolidate .. keep changes.. would you change it to Consolidate-Snapshot -Confirm:$false?

wanting to update window server, make snapshot first.. then if nothing wrong.. or no crash.. consolidate with changes..

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid there is currently no Consolidate-Snapshot cmdlet.

But you can call the API method quite easily.

Something like this

$vmTab = @{}

# Set up hash table: key = FQDN

Get-Folder "FINANS" | Get-VM | %{

    $vmTab.Add($_.Guest.HostName,$_)

}

# Loop through CSV, lookup VM on FQDN

Import-Csv C:\vm.csv -UseCulture | %{

    $vm = $vmTab[$_.fqdn]

    if($vm.Extensiondata.Runtime.ConsolidationNeeded)

    {

        $vm.ExtensionData.ConsolidateVMDisks()

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos