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?
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
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
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.
Nevermind it works! Thank you