VMware Cloud Community
SCharchouf
Hot Shot
Hot Shot
Jump to solution

Get CD / Floppy Connected Information

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 Smiley Sad

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

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

14 Replies
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

as usual LucD you are the Boss Smiley Happy

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 Smiley Happy

so for sure your help and experience are highly appreciated

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Do you mean in a CSV for example?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SCharchouf
Hot Shot
Hot Shot
Jump to solution

yep LucD, apologies if I wasn't clear

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SCharchouf
Hot Shot
Hot Shot
Jump to solution

Perfect, it's working fine Smiley Happy

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

for Floppy it should be remove the device from the VM

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

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

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Correct.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SCharchouf
Hot Shot
Hot Shot
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SCharchouf
Hot Shot
Hot Shot
Jump to solution

Thank you for kind support    

0 Kudos