VMware Cloud Community
jwmarrott
Contributor
Contributor

PowerCLI Distributed Switch Export

I like the export/import feature in v5.1 described in http://kb.vmware.com/kb/2034602

Is there a handy way to automate this with PowerCLI?  I am not looking for a generic import export script of a dvSwitch.  I have that.  I am looking for the specific PowerCLI equivalent.

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try something like this to export the dvSwitch config

$si = Get-View ServiceInstance 
$dvSwMgr
= Get-View $si.Content.dvSwitchManager

$dvsw
= Get-VirtualSwitch -Distributed -Name dvSw1
$selection = New-Object VMware.Vim.DVSSelection
$selection.dvsUuid = $dvsw.ExtensionData.Uuid

$dvswSaved
= $dvSwMgr.DVSManagerExportEntity($selection)
$dvswSaved
| Export-Clixml C:\dvswSaved.xml

And to import the dvSwitch configuration you can do

$si = Get-View ServiceInstance 
$dvSwMgr
= Get-View $si.Content.dvSwitchManager
$dvswRestore
= Import-Clixml C:\dvswSaved.xml

$dvswImport
= @() $info = New-Object VMware.Vim.EntityBackupConfig
$info
.ConfigBlob = $dvswRestore.ConfigBlob
$info
.ConfigVersion = $dvswRestore.ConfigVersion
$info.Container = $dvswRestore.Container
$info
.EntityType = $dvswRestore.EntityType
$info.Key = $dvswRestore.Key
$info
.Name = $dvswRestore.Name
$dvswImport
+= $info
$dvSwMgr
.DVSManagerImportEntity(@($dvswImport),"applyToEntitySpecified")

The reason all the properties are copied on the restore is to avoid the serialisation/deserialisation problem.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos