So in writing a script for Vcloud Director, I want to be able to see who "owns" a VM. It seems like I cannot get the vapp information from the VM.
Any ideas? Below is some of the code that I am working on:
foreach($vm in get-CiVM){
$vapp = get-Civapp | $VM
$row = "" | Select "Name", "VApp", "Org", "Status", "Operating System", "CpuCount", "Memory (GB)", Owner
$row."Name" = $_.Name
$row."Vapp" = $Vapp.Name
$row."Org" = $Vapp.Org
$row."Status" = $_.Status
$row."Operating System" = $_.GuestOSFullName
$row."CpuCount" = $_.CpuCount
$row."Memory (GB)" = ($_ | Measure-Object -Property MemoryMB -Sum).Sum/1024
$row.Owner = $vapp.Owner
If we iterate through vapps showing the vapp properties first, it will only retreve the first VM in the vapp, making the data incomplete... so we are forced to get all the VMs, then try to retrieve the vapp info - such as owner and eventually the "sizeGB" info as well.
This will show what I want, but does not retreive ALL of the VMs.
foreach($Vapp in Get-CiVapp -Name $vapp){
$vm = $vapp | get-civm
if($vm) {
$vm | %{
$row = "" | Select "Name", "VApp", "Org", "Status", "Operating System", "CpuCount", "Memory (GB)", Owner
$row."Name" = $_.Name
$row."Vapp" = $Vapp #we know the vapp already
$row."Org" = $_.Org
$row."Status" = $_.Status
$row."Operating System" = $_.GuestOSFullName
$row."CpuCount" = $_.CpuCount
$row."Memory (GB)" = ($_ | Measure-Object -Property MemoryMB -Sum).Sum/1024
$row.Owner = $vapp.Owner
Any help is much apprciated!
I've edited your code. Be sure to use more variables in future, also try use the correct terminology for them:
CIvApp = Cloud Infrastructure vApp. Collection of CIvms (One created in vCloud Director)
CIvm = Cloud Infrastructure vm. A single VM inside a CIvApp
$CIvApp = get-CIvApp "CIvAPP Name"
$CIvms = $CIvApp | get-CIvm
$report = @()
foreach($vm in $CIvms){
$row = "" | Select "Name", "CIVApp", "Org", "Status", "Operating System", "CpuCount", "Memory (GB)", "Owner"
$row."Name" = $vm.Name
$row."CIvapp" = $CIVapp.Name
$row."Org" = $CIVapp.Org.Name
$row."Status" = $CIVapp.Status
$row."Operating System" = $vm.GuestOSFullName
$row."CpuCount" = $vm.CpuCount
$row."Memory (GB)" = ($vm | Measure-Object -Property MemoryMB -Sum).Sum/1024
$row."Owner" = $CIvapp.Owner.Name
$report += $row
}
$report | Out-GridView
If there is something missing let me know.