Hello ,
I need a powercli script for list of VMs with floppy drive present.
Thanks .
$vmsWithFloppy = Get-VM | ? { ($_ | Get-FloppyDrive) -ne $null }Hi again,
If you want to remove a floppy from a Virtual Machine check online documentation about Remove-FloppyDrive
Check the example - it is exactly your case. I've build this script in 10 minutes.
Modifying the previous script:
function RemoveFloppyDrivesFromVMs( $vmsWithFloppy){
foreach ( $vm in $vmsWithFloppy){
$returnPreviousState = $false
if ( $vm.PowerState -ne "PowerOff"){
$returnPreviousState = $true
Stop-VM -VM $vm -Confirm:$false
}
#removing a floppy requires each vm to be in PoweredOff state
$vm | Get-FloppyDrive | Remove-FloppyDrive -Confirm:$false
#returning a VM to started if it was started before this script execution
if($returnPreviousState){
Start-VM -VM $vm -Confirm:$false
}
}
}
$vmsWithFloppy = Get-VM | ? { ($_ | Get-FloppyDrive) -ne $null }
RemoveFloppyDrivesFromVMs $vmsWithFloppy
You must collect all VmsWithFloppys as in the first reply I gave you
and then invoke this function with the result array $vmsWithFloppys
What this script does is removes a floppy from each vm you pass,
but because it must be powered off to remove a floppy, it remembers it's previous state(if started)
and after removal, restarts the VM again if required.
I think this will work for you.
Best regards,
Leni Kirilov
PowerCLI Team
Hi, cemdur,
You can check the documentation of Get-VM here
As you can see it returns an array of objects of type "VirtualMachine"
You can perform the following steps:
1. Connect to your VC/ESX
2. Get all your VM's
3. Pass each VM of the result array to the Get-FloppyDrive cmdlet and filter them by the result of it.
if it returns $null - you don't need this VM
if it is not $null - you need that VM
This is basically the logic behind your needed script.
Here's the PowerCLI script:
$vmsWithFloppy = Get-VM | ? { ($_ | Get-FloppyDrive) -ne $null }
Best regards,
Leni Kirilov
PowerCLI Team
Le
Yes, So that we can hunt down the VM with floppy and then remove it manually or better yet scripted to remove the vFloppyDisk Drive. Because nowadays vFloppy is no use with modern Guest OS
$vmsWithFloppy = Get-VM | ? { ($_ | Get-FloppyDrive) -ne $null }Hi again,
If you want to remove a floppy from a Virtual Machine check online documentation about Remove-FloppyDrive
Check the example - it is exactly your case. I've build this script in 10 minutes.
Modifying the previous script:
function RemoveFloppyDrivesFromVMs( $vmsWithFloppy){
foreach ( $vm in $vmsWithFloppy){
$returnPreviousState = $false
if ( $vm.PowerState -ne "PowerOff"){
$returnPreviousState = $true
Stop-VM -VM $vm -Confirm:$false
}
#removing a floppy requires each vm to be in PoweredOff state
$vm | Get-FloppyDrive | Remove-FloppyDrive -Confirm:$false
#returning a VM to started if it was started before this script execution
if($returnPreviousState){
Start-VM -VM $vm -Confirm:$false
}
}
}
$vmsWithFloppy = Get-VM | ? { ($_ | Get-FloppyDrive) -ne $null }
RemoveFloppyDrivesFromVMs $vmsWithFloppy
You must collect all VmsWithFloppys as in the first reply I gave you
and then invoke this function with the result array $vmsWithFloppys
What this script does is removes a floppy from each vm you pass,
but because it must be powered off to remove a floppy, it remembers it's previous state(if started)
and after removal, restarts the VM again if required.
I think this will work for you.
Best regards,
Leni Kirilov
PowerCLI Team
Thank you once again for the great script man !
thanks for the help