11 Replies Latest reply on Dec 11, 2017 6:12 AM by LucD

    Unwanted Hardware Report

    pamiller21 Enthusiast

      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. Re: Unwanted Hardware Report
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          Perhaps something like this?

           

           

          Get-VM | where{(Get-FloppyDrive -VM $_) -or (Get-UsbDevice -VM $_)} | Select Name

           

          • 2. Re: Unwanted Hardware Report
            pamiller21 Enthusiast

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

            • 3. Re: Unwanted Hardware Report
              LucD Guru
              vExpertCommunity WarriorsUser Moderators

              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}}

               

              • 4. Re: Unwanted Hardware Report
                pamiller21 Enthusiast

                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

                • 5. Re: Unwanted Hardware Report
                  LucD Guru
                  User ModeratorsvExpertCommunity Warriors

                  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

                  • 6. Re: Unwanted Hardware Report
                    pamiller21 Enthusiast

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

                    • 7. Re: Unwanted Hardware Report
                      LucD Guru
                      Community WarriorsvExpertUser Moderators

                      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

                      • 8. Re: Unwanted Hardware Report
                        pamiller21 Enthusiast

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

                        • 9. Re: Unwanted Hardware Report
                          LucD Guru
                          Community WarriorsUser ModeratorsvExpert

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

                          • 10. Re: Unwanted Hardware Report
                            ar264285 Lurker

                            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

                            • 11. Re: Unwanted Hardware Report
                              LucD Guru
                              vExpertCommunity WarriorsUser Moderators

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