VMware Cloud Community
roeschuxxx
Contributor
Contributor

Format issue by working with get-view output

Hi

I try to create a simply script which generates a csv file with little info about vm's. So loop over the vm's in a cluster

.....

foreach($vm in $vms){

$vminfo = "" | Select Name, Host, Cluster, GuestOS, PowerState

$VMCluster = get-cluster -VM $vm.Name

$VMPowerState = $vm.PowerState

$VMGuestOS = get-view –viewtype VirtualMachine –filter @{“Name”="$vm"} -Property @("Guest.GuestFullName") | Select -Property @{N="Running OS";E={$_.Guest.GuestFullName}}

   

    $vminfo.Name = $vm.Name

    $vminfo.Cluster = $VMCluster.Name

    $vminfo.GuestOS = $VMGuestOS

    $vminfo.PowerState = $VMPowerState

    $allvminfo += $vminfo

}

$allvminfo | Select Name, Cluster, GuestOS, PowerState | Export-Csv -path “c:\inetpub\wwwroot\cloud01.csv” -NoTypeInformation

...

The csv output looks like this

"Name","Cluster","GuestOS","PowerState"

....

"vm2.local.com","cloud1","VMware.Vim.VirtualMachine","PoweredOn"

"vm1.local.com","cloud1","VMware.Vim.VirtualMachine","PoweredOff"

....

So there is a problem with reading out the Guest OS which is instead "VMware.Vim.VirtualMachine" in the Output

Any advice?

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

Just replace the line with the Get-View by this

    $VMGuestOS = $vm.ExtensionData.Guest.GuestFullName


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos