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
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
You can just pipe the output to the Export-Csv cmdlet
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
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.
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
as usual LucD you are the Boss
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
so for sure your help and experience are highly appreciated
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
yep LucD, apologies if I wasn't clear
You can just pipe the output to the Export-Csv cmdlet
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
Perfect, it's working fine
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
By disable do you mean disconnected?
Or remove the device from the VM?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
for Floppy it should be remove the device from the VM
The VM needs to be powered off for that.
You could do
Get-FloppyDrive | Remove-FloppyDrive -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm affraid that powering OFF VM isn't an option so what you have shared can be implemented only if the VM is powerd OFF, right?
Correct.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Opps then this is not allowed, do you know another way to change this settings?
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
Thank you for kind support