Network vCenter

VDS Export/Import with PowerCLI

One of the great new features introduced in vSphere 5.1 was the ability to export and import the configuration of your vSphere Distributed Switch (VDS) and port groups to a file.

This gives you a quick restore method in case of issues or misconfigurations and also allows you to copy the entire VDS or port group configuration to a new VDS.  This feature is detailed by this VMware KB and is available via the vSphere Web Client, below you can see how we would do this via the web client:

image

Exporting the configuration with PowerCLI

With the introduction of the VDS cmdlets in PowerCLI 5.1 R2 we can also automate this process using the Export-VDSwitch and

Export-VDPortGroup cmdlets, the following examples show how we might do this:

SNAGHTML4564272

We can also choose to backup each port group configuration individually, the following example shows how to do this for a single port group:

SNAGHTML45b9f51

But what if we wanted to back up all our port groups for that VDS individually, we can easily achieve this with the following:

SNAGHTML4602062

The code used for this example is as follows:

Get-VDSwitch -Name VDS-01 | Get-VDPortgroup | Foreach {
Export-VDPortGroup -VDPortGroup $_ -Description “Backup of $($_.Name) PG” -Destination “C:\Backups\$($_.Name).Zip”
}

Importing the configuration with PowerCLI

Now we have the exported configuration the next step is to look at how we could import these files again back into vCenter if an issue happened.  Of course each file could be imported from the vSphere web client individually but this post will show you how to do this with PowerCLI.

image

The code used in this example is as follows:

Get-ChildItem “C:\Backups\PG” | Foreach {
New-VDPortgroup -VDSwitch NewVDS -Name “New$($_.BaseName)” -BackupPath $_.FullName
}

As you can see from the below, we now have two DVS which have the same configuration:

image

Conclusion

Backing up the VDS and port group configuration can not only give you a backup in case of emergency but can also be useful for creating new switches with the same configuration, one use case for example is moving the VDS configuration between vCenters, like test & dev to Production.  The above examples show you how to automate this process with PowerCLI.

Don’t forget, the backup script could easily be scheduled to export on a weekly basis so that you have the latest configuration and multiple points in time to go back to.

Check out other new features in PowerCLI 5.1 R2 here