VMware Horizon Community
nary4484
Enthusiast
Enthusiast

Can I script changing the default snapshot in a pool?

I'm looking to automate the process of changing the default snapshot in a floating pool.  I've inserted a picture to hopefully better explain the image/snap I'm talking about:

Capture.PNG

I'm not too familiar with Power Shell or PowerCLI and would like to turn this into a learning experience.  If there isn't any specific way you know of I'm also interested in sites that would be useful for someone wanting to start scripting in View.

Reply
0 Kudos
3 Replies
techguy129
Expert
Expert

As a first step, I recommend taking a look at the Vmware.HV.Helper module. You may be able to use the Set-HVPool and pass in a json file with your settings. I've not specifically done this so I don't have available code for you.

PowerCLI-Example-Scripts/Modules/VMware.Hv.Helper at master · vmware/PowerCLI-Example-Scripts · GitH...

The other option is to do it using the View API directly. My preferred method. The site isn't currently working but here is the link.

View API - VMware API Explorer - VMware {code}

To change the parent vm setting, it is in the data object DesktopVirtualCenterNamesData. There is a method called Desktop_Update you can execute that will update the pool.

One of the parameters for the method for Desktop_Update is DesktopInfo, which has a properties of automatedDesktopData which takes an data object called DesktopAutomatedDesktopData.  DesktopAutomatedDesktopData has a properties virtualCenterNamesData which takes in data object DesktopVIrtualCenterNamesData. There is where you define your parentVM.

I'd have the links to the data objects but website is down at the moment.

I hope this helps.

Reply
0 Kudos
kkdmcn
Contributor
Contributor

I have the same question.

Seems that properties ParentVM and Snapshot are read-only.

Reply
0 Kudos
jrodsguitar
Enthusiast
Enthusiast

I have a script that recomposes pools automatically. It uses some of the VMware.HV.Helper module.

Below is a snippet of how I get the pool name, get the master image name, get the location in vsphere, delete the old parent image, create a new parent image, create a new snapshot for the new parent image, and finally recompose the pool with a new parent image.

WARNING: These are just snippets of working code so you'll have to modify alot of this. Don't just try to run this because it won't work without tailoring it to your environment.

$PoolName = ((Get-HVPool -HvServer $connect) | where {$_.base.name -notlike 'Persistent*'})

$MASTERIMAGENAME = get-vm -Server $vsphere | where {$_.Name -eq $($MASTERIMAGE)}

    

$location = Get-folder 'C-Parent-Images' -Server $vsphere

               

get-vm -Name "$($CPOOLS)-Parent-$($date)" -Server $vsphere | Remove-VM -DeletePermanently -Server $vsphere -Confirm:$false

$parentvm = New-VM -Name "$($CPOOLS)-Parent-$($date)" -VM $MASTERIMAGENAME -Server $vsphere -ResourcePool 'VDI' -Datastore 'VDI - VMS' -Location $location

                               

                              

$NewSnap = New-SnapShot -VM $parentVM -name "$($CPOOLS)-Parent-$($date)" -Server $vsphere

do {write-host "snapping..." | out-string; start-sleep -sec 1}

until (get-snapshot -vm $parentVM -name "$($CPOOLS)-Parent-$($date)" -ErrorAction SilentlyContinue -Server $vsphere)

start-hvpool -Pool $PoolName -Recompose -ParentVM $parentVM -SnapshotVM $newsnap -LogoffSetting FORCE_LOGOFF -HvServer $connect

Blog: https://powershell.house/
Reply
0 Kudos