VMware Cloud Community
jessem
Enthusiast
Enthusiast

Output list to CVS or Excel

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

0 Kudos
1 Reply
RvdNieuwendijk
Leadership
Leadership

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos