Export and import customization profiles using Powershell

One great thing in the automation of VM deployments is the use of customization profiles. These profiles are stored inside the vCenter Server database. However, when you loose the database, you also loose your customization profiles. Having customization profiles exported as xml files is always useful as a backup and luckily you can export and import these profiles from within your VI client. Unfortunately this can only be done one at a time and if you have many customization profiles like me (128!) this can be a daunting task.

So I decided to pull some PowerShell code from the magic hat and wrote 2 litlle pieces of code to export and import all profiles. Both Scripts use the current directory to export and import xml files, but you can adjust this by editing the $path variable.

The Export Script

The export script exports each customization profile to its own xml file and uses the profile’s name as a file name. You can import these xml files with the import script or using your VI client.

# Variables
$VCServer = "vcserver.yourdomain.local"
$path = "."

#Connect to vCenter Server
$VC = Connect-VIServer $VCServer

#Export Customization Profiles
$view = get-view CustomizationSpecManager
ForEach ($CustomizationProfile in $view.info) {
    $xml = $view.CustomizationSpecItemToXml($view.GetCustomizationSpec($CustomizationProfile.name))
    $xml | Out-File ($path + "\" + ($CustomizationProfile.name) + ".xml")

Disconnect-VIServer -Confirm:$false

The Import Script

The import script imports all xml files in the given directory into the vCenter database.

# Variables
$VCServer = "vcserver.yourdomain.local"
$path = "."

#Connect to vCenter Server
$VC = Connect-VIServer $VCServer

#Import Customization Profiles
$view = Get-View CustomizationSpecManager
ForEach ($xmlfile in (Get-ChildItem -Path $path | where {$_.extension -eq ".xml"})) {
    $xml = Get-Content ($xmlfile)

Disconnect-VIServer -Confirm:$false

Remember to test the scripts thoroughly before using it in your production environment, as I can take no responsibility for whatever happens to your environment using these scripts.

Related posts:

  1. Reconnect ESX hosts using PowerShell Tweet This week I ran into problems with vCenter server and almost all of my VMs were orphaned in vCenter. To resolve this issue I needed to disconnect/connect each ESX...
  2. Setting custom attributes with VMware PowerCLI Tweet Last week I wanted to extend my vCenter with some extra custom attributes on my VMs. This would extend the usability of the Export List feature for reporting purposes....
  3. Bulk change your ESX root password Tweet Have you ever been facing your security department demanding you to change your ESX root password? Well I did. At the current site there’s a strict security policy where...
  4. New version of the Powershell Healthcheck script released Tweet Ivo Beerens published a new version of his Powershell Healthcheck script. Features: - VMware ESX server Hardware and version          - VMware vCenter version     - Cluster information (Updated)    ...
  5. Unattended upgrade of HP management agents Tweet After upgrading to ESX 3.5 to update3, I found out that the HP management agents needed to be upgraded to version 8.1.1, since this version supports ESX3.5 update3. So...

5 Comments on “Export and import customization profiles using Powershell”

  1. #1 RTFM Education » Blog Archive » Export and import customization profiles using Powershell
    on Jul 9th, 2009 at 4:02 pm
  2. #2 Jason Boche
    on Nov 21st, 2009 at 4:48 pm

    Thank you – these scripts saved me a lot of time today!

  3. #3 ben.neise.co.uk » Export and import customization profiles using PowerShell
    on Apr 27th, 2010 at 8:35 pm

    [...] Export and import customization profiles using Powershell | Arnim van Lieshout. [...]

  4. #4 supal
    on Jul 30th, 2012 at 5:15 pm

    thank you.

  5. #5 Export and import customization profiles using Powershell - RTFM Education – Virtualization, VMware, Citrix
    on Sep 27th, 2012 at 5:28 pm

    [...] http://www.van-lieshout.com/2009/07/export-and-import-customization-profiles-using-powershell/ .topsy_widget_shortcode,div.topsy-sm {display:inline;} .post {padding-left: 10px;}       Comment     RSS Feed     Email a friend [...]

Leave a Comment