1 Reply Latest reply on Apr 19, 2016 10:54 PM by RvdNieuwendijk

    Output list to CVS or Excel

    jessem Enthusiast

      I'm trying to export a list of VMs and their SRM state according to this script from VMware below.  However, how do I output the list/report to a csv or an excel file?

       

      vSphere 6.0 Documentation Center

       

       

      Generate a report of the protected virtual machines.

      $protectionGroups | % {

          $protectionGroup = $_

         

          $protectionGroupInfo = $protectionGroup.GetInfo()

         

          # The following command lists the virtual machines associated with a protection group

          $protectedVms = $protectionGroup.ListProtectedVms()

          # The result of the above call is an array of references to the virtual machines at the vSphere API

          # To populate the data from the vSphere connection, call the UpdateViewData method on each virtual machine view object

          $protectedVms | % { $_.Vm.UpdateViewData() }

          # After the data is populated, use it to generate a report

          $protectedVms | %{

              $output = "" | select VmName, PgName

              $output.VmName = $_.Vm.Name

              $output.PgName = $protectionGroupInfo.Name

              $output

          }

      } | Format-Table @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group name"; Expression={$_.PgName} }

        • 1. Re: Output list to CVS or Excel
          RvdNieuwendijk Virtuoso
          User ModeratorsvExpert

          You can export the output of your script to a csv file called VMreport.csv, by replacing the last line with the following:

           

          } | Select-Object -Property @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group name"; Expression={$_.PgName} } |

          Export-CSV -Path VMreport.csv -NoTypeInformation -UseCulture