vespavbb
Enthusiast
Enthusiast

export / import VM Networkportgroup info

Hi,

I would like to export the network info of some VM´s with multible Adapters and different Portgroups for some backup/restore reasons.

the Export looks fine so far, but how can I use the file to restore the portgroup configuration of each vm

$list = Get-Content "C:\test\list.txt" #| Get-Content
$includeVM = Get-Cluster test01 | Get-VM | where{$list -contains $_.Name} | Sort-Object -Property Name
$includeVM

$vmnetworkinfo =
foreach($vm in $includeVM){

    foreach($nic in Get-NetworkAdapter -VM $vm){

        Get-VirtualPortGroup -Name $nic.NetworkName -VM $vm |

        Select @{N='VM';E={$vm.Name}},

            @{N='vNIC';E={$nic.Name}},
            @{N='Adapter';E={$_.Name}}
            }
            }

$vmnetworkinfo |  Export-Csv -Path C:\Test\vmnetworkinfo.csv -NoTypeInformation -UseCulture

 

VCP4,VCP5,VCP6
0 Kudos
6 Replies
LucD
Leadership
Leadership

Are you only using VSS switches? No VDS?
The vSwitch info in your export is missing.
What about settings like VlanID and SecurityPolicy.


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

0 Kudos
vespavbb
Enthusiast
Enthusiast

Hi Luc,

it is an VDS, but I dont like to restore the portgroups and settings

I only need to restore the VM Portgroup relationship and mapping from a file, the VDS it self is not important.

the challance here is that some vm´s have more adapters..

VCP4,VCP5,VCP6
0 Kudos
vespavbb
Enthusiast
Enthusiast

Maybe I found a simple solution.

what do think about?

 

$restoreinfo = Import-Csv -Path "C:\test\vmnetworkinfo-test.csv" -Delimiter ";"

foreach ($line in $restoreinfo)
{
$vmobj  = get-vm $line.vm

$DesPGname = $line.Portgroup
$adapter =  $line.Adapter

$vmobj  | Get-NetworkAdapter |  where {$_.name -eq "$adapter"} | Set-NetworkAdapter -Portgroup $DesPGname -Confirm:$false #-RunAsync


}
VCP4,VCP5,VCP6
0 Kudos
LucD
Leadership
Leadership

Yes, that should work


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

0 Kudos
vespavbb
Enthusiast
Enthusiast

yes works:-)

but it will set the network to value even if it already correct, do I need to worry about it?

 

I had troube with some switch paramter.

what kind of switch is correct in this case? -eq, -like, -match...? The adapter is like a name!

Get-NetworkAdapter |  where {$_.name -eq "$adapter"}

 

VCP4,VCP5,VCP6
0 Kudos
LucD
Leadership
Leadership

That shouldn't be a problem.

Instead of a Where-clause, you can also use the Name parameter on the Get-NetworkAdapter cmdlet.


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

0 Kudos