VMware Cloud Community
ImaRelic
Contributor
Contributor

Need help with Get-CIVApp and count

I've been struggling for many hours with what seems like it should be a fairly simple matter.

I need to retrieve the vApp status with separate counts for VMs on and VMs off. Something along the lines of-

$vApps = Get-CIVApp -OrgVdc "MyVDC" | Select-Object Status, `
@{N="AppsOn";E={(where{$_.Status -eq "PoweredOn"}).count}}, `
@{N="AppsOff";E={(($_.Status -eq "PoweredOff").count)}}
 

 

I've tried all sorts of solutions with where, where-object, .contains and others but I can't seem to get the syntax correct.

Thanks very much in advance for any suggestions.

Labels (1)
0 Kudos
1 Reply
Algotec
Contributor
Contributor

Why do you need to stuff it all in one line?
It's much easier for me to split it into multiple lines.

 

cls
Connect-CIServer -Server "vCloud" -User "user" -Password "password"

##=VApps=##
$VApps = Get-CIVapp -OrgVdc "MyVDC"

$VAppsStatus = $VApps | Sort Status | Select Name, Status
$VAppsOn = $VAppsStatus | where{$_.Status -eq "PoweredOn"}
$VAppsOff = $VAppsStatus | where{$_.Status -eq "PoweredOff"}
$VAppsCount = ($VAppsStatus | measure).count
$VAppsOnCount = ($VAppsOn | measure).count
$VAppsOffCount = ($VAppsOff | measure).count
Write-Host ""

##=VMs=##
$VMs = Get-CIVM -VApp $VApps

$VMsStatus = $VMs | Sort Status | Select Name, Status
$VMsOn = $VMsStatus | where{$_.Status -eq "PoweredOn"}
$VMsOff = $VMsStatus | where{$_.Status -eq "PoweredOff"}
$VMsCount = ($VMsStatus | measure).count
$VMsOnCount = ($VMsOn | measure).count
$VMsOffCount = ($VMsOff | measure).count
Write-Host ""

##=STATUSES=##
cls
Write-Host VAppsCount $VAppsCount
Write-Host VAppsOnCount $VAppsOnCount
Write-Host VAppsOffCount $VAppsOffCount

Write-Host VMsCount $VMsCount
Write-Host VMsOnCount $VMsOnCount
Write-Host VMsOffCount $VMsOffCount

$VAppsStatus | OGV -Title VAppsStatus
$VMsStatus | OGV -Title VMsStatus

 

0 Kudos