PowerCLI

 View Only
  • 1.  Get All VMs in all clusters and list their OS Script

    Posted Feb 22, 2017 04:07 PM

    Hey Everyone,

    Having a hard time writing what seems like it should be a simple script. I just need to get a list of all VMs with their powered on status, OS, disk type and export that to a csv. So far what i have doesn't really work:

    get-vm |  Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}}

    Export-Csv -NoTypeInformation C:\Scripts\getvms.csv

    Any ideas?



  • 2.  RE: Get All VMs in all clusters and list their OS Script
    Best Answer

    Broadcom Employee
    Posted Feb 22, 2017 04:16 PM

    Doing the below should work:

    $details = get-vm |  Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}}

    $details | Export-CSV -NoTypeInformation C:\Users\iaasadmin\Desktop\getvms.csv

    Or you can club both the statements together by piping the output to Export-CSV like below:

    get-vm |  Select Name,@{N="Configured OS";E={$_.ExtensionData.Config.GuestFullname}},@{N="Running OS";E={$_.Guest.OsFullName}}, @{N="Powered On";E={ $_.PowerState -eq “PoweredOn”}}, @{N="disktype";E={(Get-Harddisk $_).Storageformat}} | Export-CSV -NoTypeInformation C:\Users\iaasadmin\Desktop\getvms.csv



  • 3.  RE: Get All VMs in all clusters and list their OS Script

    Posted Feb 22, 2017 05:04 PM

    Could you test it please? When running the script, it looks like it processes for awhile and then stops without errors, but i do not see a csv file in the folder.



  • 4.  RE: Get All VMs in all clusters and list their OS Script

    Posted Feb 22, 2017 05:42 PM

    Nevermind it works! Thank you