DericVMW
Contributor
Contributor

Get All VMs in all clusters and list their OS Script

Jump to solution

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?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
sajal1
VMware Employee
VMware Employee

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

View solution in original post

0 Kudos
3 Replies
sajal1
VMware Employee
VMware Employee

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

0 Kudos
DericVMW
Contributor
Contributor

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.

0 Kudos
DericVMW
Contributor
Contributor

Nevermind it works! Thank you

0 Kudos