RSS

Tag Archives: vdswitch

PowerCLI: Backup VDswitch and VDportgroups

Here is a quick set of scripts to export and backup your VDswitches. It is pretty straight forwards. It dumps VDswitch exports with and without port groups and the VDportgroups into their own folders. Then zip up each folder and finally create an archive from that 3 folders into a single backup zip. You can delete the folders and the other zip files after it ran successfully

#first connect to your vcenter with linked mode if you have


New-Item -Name noportgroup_vdswitch -ItemType Directory
Get-VDSwitch | % {Export-VDSwitch -VDSwitch $_ -Destination ".\noportgroup_vdswitch\NoPort_$($_.datacenter)_$($_.name)_$($_.id).zip" -WithoutPortGroups }
Compress-Archive -Path .\noportgroup_vdswitch -DestinationPath .\noportgroup_vdswitch



New-Item -Name fullportgroup_vdswitch -ItemType Directory
Get-VDSwitch | % {Export-VDSwitch -VDSwitch $_ -Destination ".\fullportgroup_vdswitch\fullport_$($_.datacenter)_$($_.name)_$($_.id).zip" }
Compress-Archive -Path .\fullportgroup_vdswitch -DestinationPath .\fullportgroup_vdswitch

New-Item -Name vdportgroup -ItemType Directory
Get-VDPortgroup | % { Export-VDPortGroup -VDPortGroup $_ -Destination ".\vdportgroup\PG_$($_.datacenter)_$($_.vdswitch)_$($_.name)_$($_.id).zip" }
Compress-Archive -Path .\vdportgroup -DestinationPath .\vdportgroup


Compress-Archive -LiteralPath .\vdportgroup.zip,.\fullportgroup_vdswitch.zip,.\noportgroup_vdswitch.zip -DestinationPath .\vdswitch_backup_$($(date).tostring("yyyyMMdd"))
 
Leave a comment

Posted by on June 26, 2020 in powercli, vmware

 

Tags: ,

PowerCLI: Getting VMHosts, PortGroups and switches info

I needed to extract a list of hosts in vCenter and with them, get all the portgroups and switch info. Unfortunately, there is no one one-liner script that can do this. Mainly because you have standard and distributed switches and their properties are different. In order to do this you need to separate one-liner, both feeding into the same output file.

The first script output the hosts against their VDSwitches. The script creates a tab-delimited text file that you can easy copy and paste onto a spreadsheet. Both scripts output the following:
– Clustername
– Hostname
– virtual network adapter name
– IP
– subnet mask
– port group name
– switch name
– VLAN ID

Get-VMHostNetworkAdapter -vmkernel | 
% { $vnet=$_ ; get-vdportgroup -vmhostnetworkadapter $vnet | 
%{"$($vnet.vmhost.parent)`t$($vnet.vmhost)`t
$($vnet.name)`t$($vnet.ip)`t$($vnet.subnetmask)`t
$($_.name)`t$($_.vdswitch)`t$($_.vlanconfiguration)" | 
out-file .\temp\output.txt -append } }

The second script output the hosts against their standard switch, as you can see the order of the function is very different. The main reason is that VMHostNetworkAdapter object cannot be pipped into the VirtualPortGroup but it works the other way around.

You can also see from the second script the the names for virtualswitch and vlanID different from the above. Actually .vdswitch and .vlanconfiguration are objects themselves, but they are nice enough to output the values I want without needing to specify the actual object, i.e. switch name and VLAN ID.

Get-VirtualPortgroup -standard | 
% { $pg=$_ ; get-vmhostnetworkadapter -portgroup $pg | 
% { "$($_.vmhost.parent)`t$($_.vmhost)`t$($_.name)`t
$($_.ip)`t$($_.subnetmask)`t$($pg.name)`t
$($pg.virtualswitch.name)`t$($pg.vlanid)" |
 out-file .\temp\output.txt -append }}
 
Leave a comment

Posted by on March 31, 2017 in powershell, vmware

 

Tags: , , , ,