Home > Blogs > VMware PowerCLI Blog


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

This entry was posted in Network, vCenter and tagged , , on by .
Alan Renouf

About Alan Renouf

Alan Renouf is a Product Manager at VMware focusing on Automation Frameworks and CLI, he is responsible for providing the architects and operators of the cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/PowerCLI and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

3 thoughts on “VDS Export/Import with PowerCLI

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>