This script takes the name of one or more VMWare host as input and lists all configured port groups.

# List VMWare Virtual Machine Port Groups

[CmdletBinding()]
param([Parameter(ValueFromPipeline = $true, Mandatory = $true)][String]$VMHost)

PROCESS{
	$portgroups = Get-View -ViewType HostSystem -Property Config.Network.Portgroup -Filter @{"Name"="$VMHost"}
	foreach ($portgroup in $portgroups.Config.Network.Portgroup){
	
		$obj = New-Object -TypeName PSObject
		$obj | Add-Member -MemberType 'NoteProperty' -Name VMHost -Value $VMHost
		$obj | Add-Member -MemberType 'NoteProperty' -Name vSwitch -Value (($portgroup.Vswitch).Split("-"))[-1]
		$obj | Add-Member -MemberType 'NoteProperty' -Name Key -Value (($portgroup.Key).Split("-"))[-1]
		Write-Output $obj	
	}	
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s