5.2

Table Of Contents
VMware, Inc. 49
Chapter 3 Using View PowerCLI
$localcount = ([Object[]]($locals)).Count
}
# Calculate the total number of sessions
$totalcount = $localcount + $remotecount
# Determine the maximum number of desktops configured for a pool.
$maxdesktops = 0
if($Pool.deliveryModel -eq "Provisioned"){
$maxdesktops = $Pool.maximumCount
} else {
$maxdesktops = $Pool.machineDNs.split(";").Count
}
# Output the usage statistics for a pool.
Write-Output ("==== " + $Pool.pool_id + " ====")
Write-Output ("Remote session count: " + $remotecount)
Write-Output ("Local session count: " + $localcount)
Write-Output ("Total session count: " + $totalcount)
Write-Output ("Maximum desktops: " + $maxdesktops)
# If a pool is using all its desktops, increase its maximum size
# or output a warning if it cannot be resized.
if($maxdesktops -eq $totalcount){
if($Pool.deliveryModel -eq "Provisioned"){ # Pool type can be resized
$newmaximum = [int]$Pool.maximumCount + [int]$increment
if($Pool.desktopSource -eq "VC"){ # Resize an automatic pool
Update-AutomaticPool -pool_id $Pool.pool_id -maximumCount $newmaximum
} elseif ($Pool.desktopSource -eq "SVI"){ # Resize a linked-clone pool
Update-AutomaticLinkedClonePool -pool_id $Pool.pool_id -maximumCount $newmaximum
}
Write-Output ("Pool " + $Pool.pool_id + " is using 100% of its desktops. Maximum VMs
increased to " + $newmaximum)
} else { # Pool type cannot be resized
Write-Output ("Pool " + $Pool.pool_id + " is using 100% of its desktops. Consider
increasing its capacity.")
}
}
}
Determining Paths to vSphere Inventory Objects
Define a PowerShell function that uses vSphere PowerCLI to return the full path to a vSphere inventory object.
For a function that you can use to determine datastore paths, see “Determining Paths to vSphere Datastore
Objects” on page 50.
# VVGetInventoryPath
# Parameters
# $InvObject Inventory object in vSphere PowerCLI.
#
# Examples
# VVGetInventoryPath (Get-VM -name myVM)
# VVGetInventoryPath (Get-ResourcePool | Select -first 1)
function VVGetPath($InvObject){
if($InvObject){
$objectType = $InvObject.GetType().Name
$objectBaseType = $InvObject.GetType().BaseType.Name
if($objectType.Contains("DatastoreImpl")){
Write-Error "Use the VVGetDataStorePath function to determine datastore paths."
break
}
if(-not ($objectBaseType.Contains("InventoryItemImpl") -or
$objectBaseType.Contains("FolderImpl") -or
$objectBaseType.Contains("DatacenterImpl") -or
$objectBaseType.Contains("VMHostImpl") ) ){