Manage and Repair Machine Catalogs in #XenApp/#XenDesktop 7 using #PowerShell

If you are using Machine Creation Services (MCS) extensively, you strongly depend on the hosting infrastructure. But sometimes it becomes necessary to reorganize the structure inside the hosting infrastructure. In my case, a customer needed to rename clusters, datastores and virtual networks inside VMware vCenter. Unfortunately, machine catalogs cannot be reconfigured to accomodate for those changes. The only way to repair machine catalogs is to recreate them. That’s why I have created the following PowerShell cmdlets.

The Why

When elements like clusters, datastores and networks are renamed or moved in the hosting infrastructure, MCS does not detect those changes and cannot be forced to do so. As a consequence, MCS fails to deploy new machines and update existing machines. Mind that existing machines will work if their configuration is modified to meet the new situation in the hosting infrastructure.

The only way to repair machine catalogs, it to recreate them. In many environments this involved only a one or two dozen clicks but in complex scenarios - like mine - a customer needed to recreate more than 30 catalogs across 6 sites. That’s why I created a set of PowerShell cmdlets to automate the task. They reduced the manual work to monitoring the progress and making sure that users would be able to work in the morning.

The Where - Download

Disclaimer: Before you grab a copy of this library, be aware that you cannot rely on me to provide support nor will I be responsible for interruptions in your environment. I strongly recommend that you successfully test the cmdlets in an isolated environment before applying them in production. You are fully responsible for the changes made by the cmdlets. If you are unsure what you are doing to your environment, do not use this code.

I have placed the library in GitHub to track my changes and have a fallback in case something happens to my code. Feel free to download, modify and distribute the code. It would be great if you let me participate from your corrections and enhancements!

I have also create a cmdlet reference available here.

The How - Examples to repair machine catalogs

I have created cmdlets to cover the following tasks:

In the end, I used the following process to recreate the machines catalogs based on the new cluster, datastore and network names:

  1. Create a new hosting connection (optional because a hosting connection can have multiple resources)
  2. Create a new hosting resource to reference the new cluster, datastore and network names
  3. Export all machine catalogs to a CSV file
  4. Correct the HostingUnitName to match the new hosting connection and resources
  5. Correct the path to the MasterVMImage
  6. Create new machine catalogs based on the settings in the CSV file and append a suffix to the name (and wait for the creation to complete)
  7. Add the same number of machines to the new catalog as there are in the existing catalog
  8. Substitute the existing with the new machines in the delivery group
  9. Remove the old machine catalogs
  10. Rename the new machine catalogs to remove the suffix introduced in bullet 6

So far, I have not created cmdlets for more tasks that may be useful in MCS based environments. I may extend the need arises.

The Who - Credits

This would have been a much harder task if it wasn’t for Aaron Parker (@stealthpuppy) and Stephane Thirion (@archynet) who have previously published examples for creating machines catalogs, updating them as well as creating hosting connections and resources. Thank you, guys, for giving me this head start.

Feedback is always welcome! If you'd like to get in touch with me concerning the contents of this article, please use Twitter.