Categories: PowerCLI

Collect vSwicth Information Using vSphere Power CLI

In this  Post  sharing the Script to collect the Virtual Standard Switch Information from vSPhere power cli to CSV file .

You can Modify  the Location of the file to save and directly apply to vSPhere Cli Window or  you can save this as .PS1  extension and run  CLI window .

Script 


&{foreach($esx in Get-VMHost){
$vNicTab = @{}
$esx.ExtensionData.Config.Network.Vnic | %{
$vNicTab.Add($_.Portgroup,$_)
}
foreach($vsw in (Get-VirtualSwitch -VMHost $esx)){
foreach($pg in (Get-VirtualPortGroup -VirtualSwitch $vsw)){
Select -InputObject $pg -Property @{N=”ESX”;E={$esx.name}},
@{N=”vSwitch”;E={$vsw.Name}},
@{N=”Active NIC”;E={[string]::Join(‘,’,$vsw.ExtensionData.Spec.Policy.NicTeaming.NicOrder.ActiveNic)}},
@{N=”Standby NIC”;E={[string]::Join(‘,’,$vsw.ExtensionData.Spec.Policy.NicTeaming.NicOrder.StandbyNic)}},
@{N=”Portgroup”;E={$pg.Name}},
@{N=”VLAN”;E={$pg.VLanId}},
@{N=”Device”;E={if($vNicTab.ContainsKey($pg.Name)){$vNicTab[$pg.Name].Device}}},
@{N=”IP”;E={if($vNicTab.ContainsKey($pg.Name)){$vNicTab[$pg.Name].Spec.Ip.IpAddress}}}
}
}
}} | Export-Csv C:\vswitch.csv -NoTypeInformation -UseCulture


Result 

Result of the script will shown like below .

ESX vSwitch Active NIC Standby NIC Portgroup VLAN Device IP
ESX-TEST-01 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 Management Network 101 vmk0 192.168.1.11
ESX-TEST-01 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 VLAN_114 114
ESX-TEST-01 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 VLAN_131 131
ESX-TEST-01 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 VLAN_132 132
ESX-TEST-01 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 VLAN_133 133
ESX-TEST-02 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 Management Network 101 vmk0 192.168.1.12
ESX-TEST-02 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 VLAN_114 114
ESX-TEST-02 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 VLAN_131 131
ESX-TEST-02 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 VLAN_132 132
ESX-TEST-02 vSwitch0 vmnic0,vmnic1,vmnic2,vmnic3 VLAN_133 133
Rajesh Radhakrishnan

Share
Published by
Rajesh Radhakrishnan

Recent Posts

NAKIVO Backup & Replication v10.8 Released With New Features

Nakivo has released its new Backup and Replication solution Nakivo v10.8, which includes support for…

2 years ago

Oracle Cloud VMware Solution and Features

Oracle Cloud VMware Solution (OCVS) provides a customer-managed, native VMware-based cloud environment hosted in Oracle…

2 years ago

Vinchin Backup and Recovery Review

Vinchin is a professional provider of data protection solutions for enterprises. It provides a series…

2 years ago

VMware Cloud Disaster Recovery (VCDR) Solution Deployment And Configuration Part 2

In my previous blog post, I have explained about VMware Cloud Disaster Recovery (VCDR) Onboarding and…

2 years ago

How to Deploy vRNI Cloud With VMC on AWS

vRealize Network Insight helps you build an optimized, highly available, and secure network infrastructure across…

2 years ago

This SysAdmin Day, WIN with Hornetsecurity!

Can you believe it's here again? SysAdmin Day is back, and with it comes endless gratitude…

2 years ago