VMware Cloud Community
pamiller21
Enthusiast
Enthusiast
Jump to solution

Unwanted Hardware Report

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?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

Is there anyway to show whether the VM listed has the USB or the Floppy?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

pamiller21
Enthusiast
Enthusiast
Jump to solution

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:

Useless Peripherals

Date and time

11/14/2017 14:42:39

VM Count

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

useless.jpg


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

Reply
0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

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'.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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:

  • stop/start your PowerShell session
  • Connect to the vCenter with it's FQDN
  • And in good Windows faashion, try rebooting your PC 🙂

Otherwise, no real advice to fix this :smileycry:


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

Reply
0 Kudos
pamiller21
Enthusiast
Enthusiast
Jump to solution

I rebooted and still same errors? I am running 6.5 release 1 build 4624819, is that a potential issue?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, I'm suffering from that same error as well, and it is intermittent, the worst ones Smiley Sad

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

Reply
0 Kudos
ar264285
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ar264285
Contributor
Contributor
Jump to solution

Thank you very much,

Reply
0 Kudos