Automation

 View Only
Expand all | Collapse all

Get CD / Floppy Connected Information

  • 1.  Get CD / Floppy Connected Information

    Posted Apr 16, 2020 04:34 PM

    Hello

    I have created the Below script in order to get information regardind CD | Floppy if they are connected or no , unfortunately isn't working :smileysad:

    I would like to obtain a report which contain all the information mentionned on the script

    Connect-VIServer -Server X.X.X.X

    $vms = Get-Content .PATH\List_VMs.txt

    write “VMs with a connected CD-ROM:”

    foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.ConnectionState.Connected -eq “true”}}) {

    write $vm.name

    }

    write “VMs with CD-ROM connected at power on:”

    foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.ConnectionState.StartConnected -eq “true”}}) {

    write $vm.name

    }

    write “VMs with CD-ROM connected as ‘Client Device’:”

    foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.RemoteDevice.Length -ge 0}}) {

    write $vm.name

    }

    write “VMs with CD-ROM connected to ‘Datastore ISO file’:”

    foreach ($vm in $vms | where { $_ | Get-CDDrive | where { $_.ISOPath -like “*.ISO*”}}) {

    write $vm.name

    }

    write “VMs with connected Floppy:”

    foreach ($vm in $vms | where { $_ | Get-FloppyDrive | where { $_.ConnectionState.Connected -eq “true”}}) {

    write $vm.name

    }

    write “VMs with floppy connected at power on:”

    foreach ($vm in $vms | where { $_ | Get-FloppyDrive | where { $_.ConnectionState.StartConnected -eq “true”}}) {

    write $vm.name

    }

    write “VMs with floppy connected as ‘Client Device’:”

    foreach ($vm in $vms | where { $_ | Get-FloppyDrive | where { $_.RemoteDevice.Length -ge 0}}) {

    write $vm.name

    }

    Disconnect-VIserver -Confirm:$false



  • 2.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 04:49 PM

    You can do something like the following.
    But, this will only work correctly when a VM has maximum 1 CD and/or 1 floppy.

    When the VM has more than 1 of either of these, you will have to decide how you are going to display this.

    Connect-VIServer -Server X.X.X.X

    Get-VM -Name (Get-Content .PATH\List_VMs.txt) |

    ForEach-Object -Process {

        $cd = Get-CDDrive -VM $_

        $floppy = Get-FloppyDrive -VM $_

        $_ | Select @{N='VM';E={$_.Name}},

        @{N='CD';E={$cd.Name}},

        @{N='CD Start Connected';E={$cd.ConnectionState.StartConnected}},

        @{N='CD Connected';E={$cd.ConnectionState.Connected}},

        @{N='CD Client Device';E={$cd.RemoteDevice}},

        @{N='CD ISO';E={$cd.ISOPath}},

        @{N='Floppy';E={$floppy.Name}},

        @{N='Floppy Start Connected';E={$cd.ConnectionState.StartConnected}},

        @{N='Floppy Connected';E={$cd.ConnectionState.Connected}},

        @{N='Floppy Client Device';E={$cd.RemoteDevice}}

    }


    Disconnect-VIserver -Confirm:$false



  • 3.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 05:03 PM

    as usual LucD you are the Boss :smileyhappy:

    it's working but I'm trying to have this as a report because later I will need to change thes setting using also a Script

    regarding the number of devices I'm not sure as I'm managing arround 12000 VMs :smileyhappy:

    so for sure your help and experience are highly appreciated



  • 4.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 05:07 PM

    What do you mean by "I'm trying to have this as a report"?

    Do you mean in a CSV for example?



  • 5.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 05:09 PM

    yep LucD, apologies if I wasn't clear



  • 6.  RE: Get CD / Floppy Connected Information
    Best Answer

    Posted Apr 16, 2020 05:13 PM

    You can just pipe the output to the Export-Csv cmdlet

    Connect-VIServer -Server X.X.X.X

    Get-VM -Name (Get-Content .PATH\List_VMs.txt) |

    ForEach-Object -Process {

        $cd = Get-CDDrive -VM $_

        $floppy = Get-FloppyDrive -VM $_

        $_ | Select @{N='VM';E={$_.Name}},

        @{N='CD';E={$cd.Name}},

        @{N='CD Start Connected';E={$cd.ConnectionState.StartConnected}},

        @{N='CD Connected';E={$cd.ConnectionState.Connected}},

        @{N='CD Client Device';E={$cd.RemoteDevice}},

        @{N='CD ISO';E={$cd.ISOPath}},

        @{N='Floppy';E={$floppy.Name}},

        @{N='Floppy Start Connected';E={$cd.ConnectionState.StartConnected}},

        @{N='Floppy Connected';E={$cd.ConnectionState.Connected}},

        @{N='Floppy Client Device';E={$cd.RemoteDevice}}

    } | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


    Disconnect-VIserver -Confirm:$false



  • 7.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 05:24 PM

    Perfect, it's working fine :smileyhappy:

    by the way to you have any idea how we can proceed in PowerCLI to disable some devices in bulk? let say for example Foppy



  • 8.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 05:38 PM

    By disable do you mean disconnected?
    Or remove the device from the VM?



  • 9.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 05:43 PM

    for Floppy it should be remove the device from the VM



  • 10.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 05:56 PM

    The VM needs to be powered off for that.
    You could do

    Get-VM | where{$_.PowerState -eq 'PoweredOn'} |

    Get-FloppyDrive | Remove-FloppyDrive -Confirm:$false



  • 11.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 06:00 PM

    I'm affraid that powering OFF VM isn't an option :smileysad: so what you have shared can be implemented only if the VM is powerd OFF, right?



  • 12.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 06:03 PM

    Correct.



  • 13.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 06:36 PM

    Opps then this is not allowed, do you know another way to change this settings?



  • 14.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 06:39 PM

    I'm afraid not.
    This is a protection mechanism.
    From the outside (ESXi) you don't know if the guest OS is using the CD or the floppy.

    It's the same as if you would remove a harddisk while the guest OS is running.



  • 15.  RE: Get CD / Floppy Connected Information

    Posted Apr 16, 2020 06:52 PM

    Thank you for kind support