Skip to content

Set-FloppyDrive

VMware: Modifies the configuration of a virtual floppy drive

#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential,
    [Parameter(Mandatory = $true)]
    [string]$VMName,
    [string]$FloppyImagePath,
    [string]$HostDevice,
    [bool]$Connected,
    [switch]$NoMedia,
    [bool]$StartConnected
)
Process {
    try {
        $vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
        $machine = Get-VM -Server $vmServer -Name $VMName -ErrorAction Stop
        $floppy = Get-FloppyDrive -Server $vmServer -VM $machine -ErrorAction Stop
        $setArgs = @{ ErrorAction = 'Stop'; Floppy = $floppy; Confirm = $false }
        if ($PSBoundParameters.ContainsKey('FloppyImagePath')) { $null = Set-FloppyDrive @setArgs -FloppyImagePath $FloppyImagePath }
        if ($PSBoundParameters.ContainsKey('HostDevice')) { $null = Set-FloppyDrive @setArgs -HostDevice $HostDevice }
        if ($PSBoundParameters.ContainsKey('StartConnected')) { $null = Set-FloppyDrive @setArgs -StartConnected $StartConnected }
        if ($PSBoundParameters.ContainsKey('Connected')) { $null = Set-FloppyDrive @setArgs -Connected $Connected }
        if ($PSBoundParameters.ContainsKey('NoMedia')) { $null = Set-FloppyDrive @setArgs -NoMedia:$NoMedia }
        $result = Get-FloppyDrive -Server $vmServer -VM $machine -ErrorAction Stop | Select-Object *
        if ($null -ne $result) { $result | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force }
    }
    catch { throw }
    finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}

IP address or DNS name of the vSphere server

PSCredential object for authenticating with the server

Virtual machine whose floppy drive to modify

Datastore path to the floppy image file

Path to the floppy drive on the host

Connect or disconnect the floppy drive

Off

Remove media from the floppy drive

Start connected when VM powers on

An interactive directory of PowerShell scripts.