Remap Dedicated Desktops

One of my customers needed to do a complicated migration recently.  They wanted to move their View + Unidesk VDI environment from vCenter 5.1 on Windows to the vCenter Server Appliance running vCenter 6.  We moved the ESXi hosts and used them to carry the desktops over, just like we do with servers in this sort of situation, but the View stuff added to the complexity.  On the Unidesk side, there's a nice KB article that we followed, but there isn't such guidance for View.

You may not have noticed it (I sure didn't until this migration), but on the list of desktop pools, there's a column that lists the vCenter server on which that pool was created.  It turns out that the pools are irrevocably associated with the vCenter server itself and so, when you migrate vCenter servers, you have to recreate all of your desktop pools.  This customer had about 2 dozen pools; an arduous task, but ultimately not all that time consuming... until you think about the ramifications of deleting the pools.

If you're using dedicated desktops (as this customer does), the desktop pool contains the mappings that associate each Windows user account with the appropriate desktop.  If you delete and recreate the pool (putting all of the desktops back into it), you will lose that information.  We called VMware support, to see if they had any ideas, and a gentleman from Ireland politely informed me that we would have to do it all by hand.  For a bit over 1000 dedicated desktops.

What's that you say?  A boring, repetitive task that would take a human days to accomplish?  One that a human would probably introduce innumerable errors to?  Scripting it is!  VMware has a special set of PowerCLI commands specifically for interacting with View servers... and I was disappointed to find that they couldn't do what I needed.  Fortunately, I came across another tool of their's: vdmadmin.  That tool has the ability to do exactly what I need, eg. assign a specific desktop from a pool to a specific windows user.

I ended up writing the below script.  It's a PowerShell script that's designed to be run on the View Connection Server (so that it can access vdmadmin).  In order to use it, you'll first need to export the Desktop to User relationships.  Fortunately, this can be easily done from the View Administrator, by pulling up the list of all machines and pressing the "export" button in the upper right.  It'll even conveniently give you a CSV that can be easily read into PowerShell!  I had that file saved off from before we started this process (I was afraid that we might need that mapping data...) and so I put the script to work.

It has 3 parameters:
-UserMappings is the csv file that lists the users and their desktops
-Desktops is a regular expression that is used to figure out which desktops you want to remap
-ReportOnly is a switch that sets the script to not actually do anything but to only spit out what it would do.

Be careful with this; I wrote it in a hurry and didn't have time to test it thoroughly.  It worked for me in this particular situation, but that's no guarantee that it'll work for you in yours.  Test thoroughly and let me know if you fix anything!


Comments

Popular posts from this blog

Clone a Standard vSwitch from one ESXi Host to Another

PowerShell Sorting by Multiple Columns

Deleting Orphaned (AKA Zombie) VMDK Files