Find VMs with Disconnected NICs

Posted: June 26, 2012 in Scripts, VMware

Hopefully you never a situation like this, but I’ve 2 in the past couple of weeks for seperate clients. After a big batch of maintenance where all VMs in a cluster where offline, they were powered back on, but a number of vNICs were left in a disconnected state, despite being set to be connected at boot. To speed things up, this little script locates the powered on VMs, with NICs set to connect at boot, but that are currently not powered on. You could take this a step further and reconnect the NICs as well. However, in some instances the NICs are left off for a reason, so the list needed to be reviewed first.

$VMs = Get-Cluster “Cluster Name” | Get-VM | Where { $_.PowerState -eq “PoweredOn” } | Sort-Object Name

ForEach ($VM in $VMs){
$nics = $null
$nics = $vm | get-networkadapter | Where {$_.ConnectionState.Connected -eq $false -and $_.ConnectionState.StartConnected -eq $true}
If ($Nics -ne $null){
$vm.name
}
}

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s