Network related vSphere checks

The following two sections of code can be ran independently or used in conjunction with Alan Renouf’s vCheck script. They return network specific issues that could happen in a vSphere environment.

The first check makes use of a $clusters variable, which can be created using the following line of code:

$Clusters = Get-Cluster

The following section will report on any port groups that do not exist on all hosts in a cluster. This is a fairly common issue with standard vSwitches, but is typically resolved by using Distributed vSwitches (for the Enterprise Plus users).
[cc lang=”Powershell”]
$networkListHT = @{}
Get-View -ViewType Network -Property Name | %{ $networkListHT.Add($_.MoRef.value,$_.Name) }

$portGroupCheck = @()
$Clusters | Select Name, ID | %{
$thisClusterName = $_.Name
$thisClusterHosts = Get-View -ViewType HostSystem -SearchRoot $_.id -Property Name, Network

$thisClusterNetworks = @()
$thisClusterHosts | %{
$thisHost = $_.Name
$_.Network | %{ $thisClusterNetworks += New-Object psobject -Property @{ “Port Group”=$networkListHT[$_.Value]; Host=$thisHost; Cluster=$thisClusterName} }
}

$portGroupCheck += ($thisClusterNetworks | Group-Object -Property “Port Group” | ?{$_.Count -lt $thisClusterHosts.count} | Select -ExpandProperty Group | Sort Host )
}

$portGroupCheck
[/cc]

The following one liner will show any port group that does not have virtual machines. This could be a new network that simply doesn’t have VMs yet, or an old network that is no longer required.
[cc lang=”powershell”]
Get-View -ViewType Network -Property Name, VM, Host |?{@($_.VM).Count -eq 0} | Select Name, @{Name=”Host Count”; Expression={@($_.Host).Count}} | Sort Name
[/cc]

This entry was posted in Scripting, Virtualization. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.