Those who may have come across one of my other posts about using PowerShell to initiate desktop catalog refreshes within Citrix’s XenDesktop 5.5 will recall about my complaint towards the responsiveness of the GUI and unfortunately, I find VMware View’s View Administrator console just as sluggish and is quite painful to use to recompose multiple desktop pools. So as with my post for Citrix XenDesktop’s catalog refresh, I have opted to prepare PowerCLI cmdlets that I can simply modify to recompose all of the virtual desktops in a desktop pool. As I searched for the PowerCLI commands that were available for VMware View, I quickly found that the documentation was sparse and definitely not as available as Citrix’s PowerShell commands (note that I didn’t find Citrix’s documentation that complete but was easily able to find the API through Google). In any case, the following demonstrates how to retrieve the information you need to update all of the virtual desktops in a pool with a snapshot.
One of the few documents I was able to find from VMware that describes how to update a pool is the following:
Recompose all linked-clone desktops from a snapshot of their parent virtual machine.
Get-DesktopVM -pool_id lcdpool_2 | Send-LinkedCloneRecompose -schedule ((Get-Date).AddHours(8)) -parentVMPath /AutoPoolVMs/parent2 -parentSnapshotPath /AutoPoolSnapshots/parent2_snapshot -forceLogoff $true -stopOnError $true
While I wasn’t able to find more details as to what other switches were available and what the descriptions of the switches used above were, it was enough to get me started so begin by launching the View PowerCLI on your View Connection server:
Once the View PowerCLI launches, execute the following to connect to the vCenter that manages the View desktops:
Connect-VIServer <vCenterIP>
Once you have successfully connected to the vCenter server, execute the following replacing the pool ID 900 with the ID for the pool you would like to update:
Get-Pool -Pool_ID 900
From the output above, the values we’re interested in are as follows:
parentVMPath – /New Datacenter/vm/View Templates/Susan-Tmp
parentVMSnapshotPath – /March 11
The parentVMPath is the path to the master image the linked-clone pool is currently using while the parentVMSnapshotPath is the path to the snapshot the linked-clone pool is currently spawned from. Assuming that you a new snapshot created for the master image, the next step is to execute the following cmdlet replacing Susan-Tmp with the virtual machine name of your master image displayed in vCenter:
Get-Snapshot Susan-Tmp
**Note that the Get-Snapshot cmdlet does not work if you did not connect to your vCenter with the Connect-VIServer cmdlet.
With the information collected with the cmdlets above, the next step is to determine how long you would like to wait from the time you execute this cmdlet before logging users off. The command in the example above uses is Get-Date and it adds 8 hours to the current time. In my case, I’m executing this cmdlet to immediately recompose the desktop pool so rather than using the AddHours command, I’m going to use the AddMinutes instead. Note that the Get-Date command allows for the following but I am not sure if VMware View PowerCLI allows for all of them to be used:
- AddDays
- AddHours
- AddMilliseconds
- AddMinutes
- AddMonths
- AddSeconds
- AddTicks
- AddYears
To recap, the following table outlines the parameter values we need and what cmdlets to use to get them:
Parameter | CMDLET to Retrieve |
Pool_ID | Get-Pool -displayName <yourPoolName> | format-list Pool_ID |
ParentVMPath | Get-Pool -pool_id <yourPoolID>| format-list displayName,parentVMPath,parentVMSnapshotPath |
ParentSnapShotPath | Get-Snapshot <yourMasterImageVMName> |
**Note that if you have multiple snapshots as shown in this example, you need to concatenate the snapshots from top to bottom with the snapshots displayed from the Get-Snapshot command. So for this example, we’re going to use the second snapshot named March 18 but because the first snapshot is March 16, we’ll need to type the parentSnapshotPath as “/March 16/March18”:
Get-DesktopVM -pool_id 900 | Send-LinkedCloneRecompose -schedule ((Get-Date).AddMinutes(2)) -parentVMPath "/New Datacenter/vm/View Templates/Susan-Tmp" -parentSnapshotPath "/March 16/March 18" -forceLogoff $true -stopOnError $true
Note that the last two switches:
- -forceLogoff
- -stopOnError
… represent the checkboxes displayed in the GUI:
- Force users to log off
- Stop at first error
Hope this helps anyone who may want to understand the requirements for recomposing a VMware View linked-clone pool via PowerCLI.
3 comments:
Hi Terence,
Thanks for your script!! Using your work, I have created a script to automate OS update for link clone pool.
http://fei-automation.blogspot.sg/2013/07/view-powercli-script-automate-linked.html
Hello:
I so badly want to use this script, however, the cmdlets don't show up on my PowerCLI. Is there a specific snapin for this, or permission level you must have?
I looked at all my registered snapins and could not the cmdlets you used (eg: get-desktopvm, set-linkedclonerecompose, etc.).
Any help or guidance would be appreciated.
Looking for script to refresh a pool in batches of 15 VM's at a time until complete.. If anyone has sugguestions.
Post a Comment