Thursday 11 August 2011

Checks for VMs with mounted floppy drives

#Description: This powershell function checks for VMs attached floppy drives
#Purpose: If floppy drives are mounted on VM, you can't VMotion the machine
#Designed to be added as function into $profile for quick-admin tasks, run from commandline


#Requires VCLI snapin - www.vmware.com/support/developer/vcli/
#Author: Kirk Munro, extracted from VMware powerpack: http://www.powergui.org/entry.jspa?externalID=1802&categoryID=290
#Tested with: ESX4.1
#Last edit by: MsMiller on 11/08/2011
function func_VMs_with_FDD_Connected()
{
$noConnection = $true
if ($defaultVIServers) {
 foreach ($managedHost in $defaultVIServers) {
  $noConnection = $false
  Get-VM -Server $managedHost | ForEach-Object {
   $vmname = $_.Name
   $flop = $_ | Get-FloppyDrive | where {$_.ConnectionState.Connected -eq $true}
   if ($flop) {
    $flop.PSObject.TypeNames.Insert(0,"$($flop.PSObject.TypeNames[0])#VmwarePowerPackExtension")
    $flop `
     | Add-Member -MemberType NoteProperty -Name VM -Value $vmname -PassThru `
     | Add-Member -MemberType NoteProperty -Name Connected $flop.ConnectionState.Connected -PassThru `
     | Add-Member -MemberType NoteProperty -Name ManagedHost -Value $managedHost.Name -PassThru
   }
  }
 }
}
if ($noConnection){
 Show-MessageBox -Text 'You must connect to one or more vSphere servers before you can run the VMs with FDD Connected best practice query on those servers. Please click on the ''Managed Hosts'' node, connect to one or more of the vSphere servers you have configured there, and then try again.' -Caption 'Connection not established' -Buttons 'OK' -Icon 'Information' | Out-Null
}
}


 func_VMs_with_FDD_Connected | Select-Object -property 'VM', 'Name', 'Connected', 'FloppyImagePath', 'HostDevice', 'RemoteDevice'