6 Replies Latest reply on Mar 23, 2011 7:02 AM by RvdNieuwendijk

    Finding VM's with attatched serial ports?

    peter79 Enthusiast

      Guys,

       

      I need a script that will find any VM's in my evviroment that have attatched serial ports and output the VM name to a CSV file.

       

      Thanks in advance guys.     

        • 1. Re: Finding VM's with attatched serial ports?
          RvdNieuwendijk Virtuoso
          vExpertUser Moderators

          The next PowerCLI script will write all the virtual machines with a serial port to a .csv file:

           

          Get-VM | ForEach-Object {
            $VM = $_
            $VM.ExtensionData.Config.Hardware.Device | ForEach-Object {
              if ($_.GetType().Name -eq "VirtualSerialPort") {
                $VM
              }
            }
          } | Export-Csv -Path VMsWithSerialPort.csv -NoTypeInformation -UseCulture 
          
          


          Regards, Robert

          • 2. Re: Finding VM's with attatched serial ports?
            peter79 Enthusiast

            Thanks for your response but the script you provided doesnt seem to list any attatched serial ports. 

            • 3. Re: Finding VM's with attatched serial ports?
              LucD Guru
              vExpertUser ModeratorsCommunity Warriors

              The output goes to a CSV file in the directory where you are located.

              • 4. Re: Finding VM's with attatched serial ports?
                peter79 Enthusiast

                Sorry I should be been clearer.  I had a look at the csv file created by the script and while there is a lot of useful data the file does not contain any data relating to serial ports.  Any ideas?

                 

                Thanks for your help so far.

                • 5. Re: Finding VM's with attatched serial ports?
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  Ok, got it. Try this

                   

                  Get-VM | ForEach-Object {
                    $VM = $_  $VM.ExtensionData.Config.Hardware.Device | ForEach-Object {
                      if ($_.GetType().Name -eq "VirtualSerialPort") {
                        $_ | Select @{N="VM";E={$vm.Name}},
                                  @{N="Type";E={$_.Backing.GetType().Name}},
                                  @{N="Label";E={$_.DeviceInfo.Label}},
                                  @{N="Backing";E={$_.Backing.DeviceName}}
                      }
                    }
                  } | Export-Csv -Path VMsWithSerialPort.csv -NoTypeInformation -UseCulture 
                  
                  • 6. Re: Finding VM's with attatched serial ports?
                    RvdNieuwendijk Virtuoso
                    User ModeratorsvExpert

                    The first time you only asked for the names of the VM's with attached serial ports. And what you ask for, is what you get.

                     

                    Although Luc already gave you a new script, I made a different one that I want to show you also.

                     

                    Get-VM | ForEach-Object {
                      $VM = $_
                      $VM.ExtensionData.Config.Hardware.Device | ForEach-Object {
                        if ($_.GetType().Name -eq "VirtualSerialPort") {
                          $Report = "" | Select-Object -Property VM,Label,Summary,StartConnected,Connected,AllowGuestControl,Status
                          $Report.VM = $VM.Name
                          $Report.Label = $_.DeviceInfo.Label
                          $Report.Summary = $_.DeviceInfo.Summary
                          $Report.StartConnected = $_.Connectable.StartConnected
                          $Report.Connected = $_.Connectable.Connected
                          $Report.AllowGuestControl = $_.Connectable.AllowGuestControl
                          $Report.Status = $_.Connectable.Status
                          $Report
                        }
                      }
                    } | Export-Csv -Path VMsWithSerialPort.csv -NoTypeInformation -UseCulture