I am looking to make a report that shows VMs with unwanted hardware attached, such as floppies or USB controllers/devices that need removed. Any details on how to do this?
Something like this?
Get-VM |
Select Name,
@{N='Serial';E={
($_.ExtensionData.Config.Hardware.Device |where {$_.DeviceInfo.Label -like "Serial Port*"} |
%{$_.DeviceInfo.Label} ) -join '|'}},
@{N='Parallel';E={
($_.ExtensionData.Config.Hardware.Device |where {$_.DeviceInfo.Label -like "Parallel Port*"} |
%{$_.DeviceInfo.Label}) -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perhaps something like this?
Get-VM | where{(Get-FloppyDrive -VM $_) -or (Get-UsbDevice -VM $_)} | Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there anyway to show whether the VM listed has the USB or the Floppy?
Something like this?
Get-VM | where{(Get-FloppyDrive -VM $_) -or (Get-UsbDevice -VM $_)} |
Select Name,
@{N='Floppy';E={(Get-FloppyDrive -VM $_) -ne $null}},
@{N='Usb';E={(Get-UsbDevioce -VM $_) -ne $null}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This script is working great, but I am attempting to push the output to an html file. This is what happens when I run just the body portion:
Name Floppy Usb
---- ------ ---
dc1-vl_replica True
radius2 True
But when I run the script to output it shows:
11/14/2017 14:42:39
2
Here is my script:
#############################
# Connect to vCenter #
#############################
Import-Module VMware.VimAutomation.Core
$vc = 'vcenter6.ruralnex.com'
$Cred = Import-Clixml C:\Scripts\mycreds.xml
Connect-VIServer $VC -Credential $Cred
#############################
# Content #
#############################
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="C:\Scripts\Temp\Perp-$date.htm"
$report = Get-VM | where{(Get-FloppyDrive -VM $_) -or (Get-UsbDevice -VM $_)} | Select Name, @{N='Floppy';E={(Get-FloppyDrive -VM $_) -ne $null}}, @{N='Usb';E={(Get-UsbDevioce -VM $_) -ne $null}}
#############################
# Add Text to the HTML file #
#############################
$report | ConvertTo-Html –title "Useless Peripherals" –body "<H1>Useless Peripherals</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation
ConvertTo-Html –title "Useless Peripherals" –body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
ConvertTo-Html –title "Useless Peripherals" –body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation
##############################
# Disconnect session from VC #
##############################
disconnect-viserver -confirm:$false
Your script is working fine for me, just made some minor changes.
$date=Get-Date -format "yyyy-MMM-d"
$datetime=Get-Date
$filelocation="C:\Temp\Perp-$date.htm"
$report = Get-VM | where{(Get-FloppyDrive -VM $_) -or (Get-UsbDevice -VM $_)} |
Select Name, @{N='Floppy';E={(Get-FloppyDrive -VM $_) -ne $null}},
@{N='Usb';E={(Get-UsbDevioce -VM $_) -ne $null}}
#############################
# Add Text to the HTML file #
#############################
$head = "<link rel='stylesheet' href='style.css' type='text/css' />"
$report | ConvertTo-Html -Title "Useless Peripherals" -Body "<H1>Useless Peripherals</H1>" -Head $head | Out-File $filelocation
ConvertTo-Html -Body "<H4>Date and time</H4>",$datetime -Head $head | Out-File -Append $filelocation
ConvertTo-Html -Body "<H4>VM Count</H4>",$report.Count -Head $head | Out-File -Append $filelocation
Invoke-Item -Path $filelocation
What type of output are you expecting?
I get
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure what I am doing wrong, but I got this now when I run this:
Get-FloppyDrive : 12/6/2017 11:46:48 AM Get-FloppyDrive Error in deserializing body of reply message for operation
'RetrievePropertiesEx'.
That "Error in deserializing body" has been seen by many users on different cmdlets I'm afraid.
No real solution for now afaik.
Some actions that seem to have helped some users:
Otherwise, no real advice to fix this :smileycry:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I rebooted and still same errors? I am running 6.5 release 1 build 4624819, is that a potential issue?
No, I'm suffering from that same error as well, and it is intermittent, the worst ones
I suggest to open a SR, that way the PowerCLI Team is aware of it, and the more reports they get about the issue, the sooner it will get fixed (I hope).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
Could you please share the script to get the Serail and parallel ports are connected on the VM List, it more helpful for me
Something like this?
Get-VM |
Select Name,
@{N='Serial';E={
($_.ExtensionData.Config.Hardware.Device |where {$_.DeviceInfo.Label -like "Serial Port*"} |
%{$_.DeviceInfo.Label} ) -join '|'}},
@{N='Parallel';E={
($_.ExtensionData.Config.Hardware.Device |where {$_.DeviceInfo.Label -like "Parallel Port*"} |
%{$_.DeviceInfo.Label}) -join '|'}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much,