Get-VMWareFloppy Cmdlet to retrieve virtual Floppy Drive configuration information


OK, I found some issue with Get-VMWareTools and Get-VMWareCDDrive CMDLET and found that the execution to query and extract information from the vCenter did not disconnect after the command is executed and therefore it lead to an issue where if you run Get-VMWareTools and decided to run Get-VMWareCDDrive CMDLET later in the same PowerShell console. In theory, it established 2 connection to the vCenter.

Hmmm… Fixed that issue by updating the Get-VMWareTools and Get-VMWareCDDrive CMDLET module to disconnect the session after process execution and perform some clean up on the PSSnapin.

Guess what? As promised, I have also done the Get-VMWareFloppy CMDLET module to retrieve the virtual floppy drive configuration information. Of Course, this Get-VMWareFloppy CMDLET does disconnect the session after process execution and perform some clean up on the PSSnapin. It is a behavior issue which I didn’t notice because I kept on closing the PowerShell console on each test.

That’s it. I have posted the Get-VMWareFloppy download link below. Have fun.

Download Link – http://gallery.technet.microsoft.com/Get-VMWareFloppy-e4c3c397

function Get-VMwareFloppy {
<#

.SYNOPSIS
    Get the VMWare Virtual Machine virtual Floppy Drive configuration information.
  
.DESCRIPTION   
    Allows the administrator to get the virtual Floppy Drive configuration information
    on the virtual machine from VMWare vCenter.

.PARAMETER ComputerName

    ALIAS -VI
    This parameter specify host connection to the VMWare vCenter

.PARAMETER GuestName

    ALIAS -Guest
    This parameter allows administrator to specify the VM Guest name

.PARAMETER Username

    ALIAS -U
    This parameter allows administrator to specify username to authenticate with the server.

.PARAMETER Password

    ALIAS -P
    This paramter allows administrator to specify the password to authenticate with the server.

.EXAMPLE
    
    This example demostrate how to import the Get-VMWareFloppy.psm1 module and use the command
    to query the VMWare vCenter for VMWare virtual Floppy Drive information on guest virtual machine
    name VM1.

    Import-Module C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Get-VMWareFloppy.psm1
    Get-VMWareFloppy -VI VMWarevCenter -U Redmond\VirtualCenterAdministrator -P C0nt0s0 -Guest VM1

    GuestName            : VM1
    VMHost               : esx11.redmond.com
    UUID                 : 4212a615-e5c9-38be-a3ed-68a749d95791
    OperatingSystem      : Microsoft Windows 8 (64-bit)
    PowerState           : Suspended
    NumberOfFloppyDrives : 1
    ChangeVersion        : 2013-10-10T03:55:08.656392Z
    DeviceID             : VirtualMachine-vm-41405/8000
    DeviceName           : Floppy drive 1
    FloppyImagePath      :
    HostDevice           :
    RemoteDevice         :
    Connected            : False
    StartConnected       : False
    AllowGuestControl    : True
    Status               : untried

.EXAMPLE
    
    This example demostrate how to generate a report of all the VMWare virtual Floppy Drive information
    for each virtual machine in VMWare vCenter and export to a CSV file.

    Get-VMWareFloppy -ComputerName VMWarevCenter | Export-Csv C:\Temp\Get-VMWareFloppy.csv -NoTypeInformation


.NOTES
    Title   : PowerShell Get VMWare virtual Floppy Drive
    FileName: Get-VMWareFloppy.psm1
    Author  : Ryen Kia Zhi Tang
    Date    : 16/10/2013
    Blog    : ryentang.blogspot.com
    Version : 1.0

#>

param(

    [Parameter(
        Mandatory=$True,
        ValueFromPipeline=$True,
        ValueFromPipelineByPropertyName=$True)]
    [Alias('VI')]
    [String] $ComputerName = $env:COMPUTERNAME,

    [Parameter(
        Mandatory=$False,
        ValueFromPipeline=$True,
        ValueFromPipelineByPropertyName=$True)]
    [Alias('U')]
    [String] $Username,

    [Parameter(
        Mandatory=$False,
        ValueFromPipeline=$True,
        ValueFromPipelineByPropertyName=$True)]
    [Alias('P')]
    [String] $Password,

    [Parameter(
        Mandatory=$False,
        ValueFromPipeline=$True,
        ValueFromPipelineByPropertyName=$True)]
    [Alias('Guest')]
    [String] $GuestName

)

    BEGIN {}

    PROCESS {

        # Add VMWare PowerCLI PSSnapin
        Add-PSSnapin VMware.VimAutomation.Core

        # Verify Username and Password parameter is not null and construct PSCredential object for authentication
        if(($Username -ne "") -and ($Password -ne "")){

            # Construct Credential
            $PWD = convertto-securestring $Password -asplaintext -force
            $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$PWD

            # Establish connection using Credential Object
            $Connection = Connect-VIServer -Server $ComputerName -Credential $Credential -Force -Verbose

        # Verify Username and Password parameter is null and use Windows Integrated Authentication
        }else{

            # Establish connection using Windows Integrated Authentication
            $Connection = Connect-VIServer -Server $ComputerName -Force -Verbose
        }

        # Verify GuestName parameter is not null
        if($GuestName -ne "") {

            # Get specific VM Guest
            $VMs = Get-VM -Name $GuestName

        }else{

            # Get all VM Guests
            $VMs = Get-VM
        }

        # Construct Result
        foreach($VM in $VMs) {

            foreach($vFloppyDrive in $(Get-FloppyDrive -VM $VM.Name)) {

                $VM | Select @{L='GuestName';E={($_.Name)}},
                @{L='VMHost';E={($VM.VMHost)}},
                @{L='UUID';E={(((($VM).ExtensionData).Config).Uuid)}},
                @{L='OperatingSystem';E={((($VM).Guest).OSFullName)}},
                @{L='PowerState';E={($VM.PowerState)}},
                @{L='NumberOfFloppyDrives';E={((Get-FloppyDrive -VM $VM.Name | Measure-Object).Count)}},
                @{L='ChangeVersion';E={(((($VM).ExtensionData).Config).ChangeVersion)}},
                @{L='DeviceID';E={($vFloppyDrive.ID)}},
                @{L='DeviceName';E={($vFloppyDrive.Name)}},
                @{L='FloppyImagePath';E={($vFloppyDrive.FloppyImagePath)}},
                @{L='HostDevice';E={($vFloppyDrive.HostDevice)}},
                @{L='RemoteDevice';E={($vFloppyDrive.RemoteDevice)}},
                @{L='Connected';E={(((($vFloppyDrive).ExtensionData).Connectable).Connected)}},
                @{L='StartConnected';E={(((($vFloppyDrive).ExtensionData).Connectable).StartConnected)}},
                @{L='AllowGuestControl';E={(((($vFloppyDrive).ExtensionData).Connectable).AllowGuestControl)}},
                @{L='Status';E={(((($vFloppyDrive).ExtensionData).Connectable).Status)}}

            }

        }
        
    }

    END { Disconnect-VIServer -Server $ComputerName -Confirm:$FALSE ; Remove-PSSnapin VMware.VimAutomation.Core }

}
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