VMware Cloud Community
jamie20
Enthusiast
Enthusiast
Jump to solution

Session Count Per Pool Report

Hi Guys,

I am trying to make a script which gives count of available, connected and disconnected sessions of all the desktop pool as a csv report.

Below is the script which gives count of available, connected and disconnected sessions of a single desktop pool.

$pool = Read-host "Enter the pool name"

$tmp = Get-HVPool -PoolName $pool | Select -ExpandProperty base | Select -expandproperty name | % {Get-HVMachineSummary -PoolName $_| Select -ExpandProperty base | Select name,basicstate}

$Dname = (Get-HVPool -PoolName $pool).base.name

$Results = New-Object PSObject -Property @{

        "Available" = ($tmp | where {$_.basicstate -eq "AVAILABLE"});

        "Connected" = ($tmp | where {$_.basicstate -eq "CONNECTED"});

        "Disconnected" = ($tmp | where {$_.basicstate -eq "DISCONNECTED"});}

$Available = ($Results.Available).Count

$Connected = ($Results.Connected).Count

$Disconnected = ($Results.Disconnected).Count

$Total = $tmp.Count

write-host "Desktoppool name:" $Dname

write-host "Total Systems in the pool are:" $Total

write-host "Available Systems in the pool are:" $Available

write-host "Connected Systems in the pool are:" $Connected

write-host "Disconnected Systems in the pool are:" $Disconnected

#End

How to get these details for all the desktoppools?

Expected csv output:

    

Desktoppool NameTotalAvailableConnectedDisconnected
Desktop-0110532
Desktop-02

Any help?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can you try something like this

Get-HVPool | ForEach-Object -Process {

     $pool = $_

     $summary = Get-HVMachineSummary -PoolName $pool.base.name

     New-Object -TypeName PSObject -Property @{

          PoolName = $pool.base.name

          StationCount = $summary.base.Count

          Available = $summary.base.basicstate.Where({$_ -eq 'AVAILABLE'}).Count

          Connected = $summary.base.basicstate.Where({$_ -eq 'CONNECTED'}).Count

          Disconnected = $summary.base.basicstate.Where({$_ -eq 'DISCONNECTED'}).Count

     }

}


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

View solution in original post

10 Replies
LucD
Leadership
Leadership
Jump to solution

Doesn't Get-HVPool without parameters return all the pools?
Then, in a loop over all the pool names (base.name), you can call Get-HVMachineSummary for each pool.


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

0 Kudos
jamie20
Enthusiast
Enthusiast
Jump to solution

Hi Lucd,

Thanks for the reply...I did something like this...

$tmp = Get-HVPool | Select -ExpandProperty base | Select -expandproperty name | % {Get-HVMachineSummary -PoolName $_ | Select -ExpandProperty base | Select name,basicstate}

ForEach-Object -Process {

$Results = New-Object PSObject -Property @{

        "Available" = ($tmp | where {$_.basicstate -eq "AVAILABLE"});

        "Connected" = ($tmp | where {$_.basicstate -eq "CONNECTED"});

        "Disconnected" = ($tmp | where {$_.basicstate -eq "DISCONNECTED"});}

$Available = ($Results.Available).Count

$Connected = ($Results.Connected).Count

$Disconnected = ($Results.Disconnected).Count

$Total = $tmp.Count

write-host "Total Systems in the pool are:" $Total

write-host "Available Systems in the pool are:" $Available

write-host "Connected Systems in the pool are:" $Connected

write-host "Disconnected Systems in the pool are:" $Disconnected

}

But this sums all the desktoppool sessions and gave as a total count.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you try something like this

Get-HVPool | ForEach-Object -Process {

     $pool = $_

     $summary = Get-HVMachineSummary -PoolName $pool.base.name

     New-Object -TypeName PSObject -Property @{

          PoolName = $pool.base.name

          StationCount = $summary.base.Count

          Available = $summary.base.basicstate.Where({$_ -eq 'AVAILABLE'}).Count

          Connected = $summary.base.basicstate.Where({$_ -eq 'CONNECTED'}).Count

          Disconnected = $summary.base.basicstate.Where({$_ -eq 'DISCONNECTED'}).Count

     }

}


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

sjesse
Leadership
Leadership
Jump to solution

Take a look at

GitHub - vCheckReport/vCheck-HorizonView: vCheck for Horizon View

it has a module that does the same as LucD 's code but also looks at all the desktop status, so you can see the sessions and desktops in invalid states at the same time. The specific modules are in

vCheck-HorizonView/Plugins/20 Desktop at master · vCheckReport/vCheck-HorizonView · GitHub

if your not interested in running the report its self. Running it though may save you some time if it servers the same function as you are trying to do.

0 Kudos
jamie20
Enthusiast
Enthusiast
Jump to solution

Awesome lucd...Works perfectly....

0 Kudos
jamie20
Enthusiast
Enthusiast
Jump to solution

Hi Jesse,

Thanks for the link...I tried those scripts, But none of it working for me....Below is the script for manual pool

$manualpoolstatus=@()

foreach ($pool in $pools){

$poolname=$pool.base.name

if ($pool.Type -like "Manual"){

$queryservice=new-object vmware.hv.queryserviceservice

$defn = New-Object VMware.Hv.QueryDefinition

$defn.queryentitytype='MachineSummaryView'

$defn.filter=New-Object VMware.Hv.QueryFilterEquals -property @{'memberName'='base.desktop'; 'value'=$pool.id}

$queryResults = $queryService.QueryService_Create($Services1, $defn)

$desktops=$queryResults.results

$manualpoolstatus+=New-Object PSObject -Property @{

"Name" = $Poolname;

"Available" = ($desktops | where {$_.base.basicstate -eq "AVAILABLE"}).count;

"Connected" = ($desktops | where {$_.base.basicstate -eq "CONNECTED"}).count;

"Disconnected" = ($desktops | where {$_.base.basicstate -eq "DISCONNECTED"}).count;

"Already_Used" = ($desktops | where {$_.base.basicstate -eq "ALREADY_USED"}).count;

"Agent_Unreachable" = ($desktops | where {$_.base.basicstate -eq "AGENT_UNREACHABLE"}).count;

"Error" = ($desktops | where {$_.base.basicstate -eq "ERROR"}).count;

}

$services1.QueryService.QueryService_DeleteAll()

}

}

$manualpoolstatus | select Name,Available,Connected,Disconnected,Already_Used,Agent_Unreachable,Error

#End

This script returns nothing...What I am missing?

0 Kudos
sjesse
Leadership
Leadership
Jump to solution

Download the whole thing here

GitHub - vCheckReport/vCheck-HorizonView: vCheck for Horizon View

they are modules that are run as part of the vcheck.ps1 file. If you follow the installing section in that same URL, it will tell you how to configure it. The part that's similar to what your trying to do will look like Connected and disconnected are your sessions, but the rest are the available machine statuses.

Linked Clone Desktop Pool Status

These are the pools that have floating linked clones. Not all but the most common status's are counted.

 

Name

Pool_Image

Pool_Snapshot

Desktop_Count

Available

Connected

Disconnected

Maintenance

Provisioning

Customizing

Already_Used

Agent_Unreachable

Error

Deleting

Provisioning_Error

EUC_ASE_ENVI_LC_PR2

/PDC/vm/~its-w7-imglcv2

/Pool Snapshot/Pool Snapshot 2

0

0

0

0

0

0

0

0

0

0

0

0

jamie20
Enthusiast
Enthusiast
Jump to solution

Hi Jesse,

This vcheck is working and seems highly efficient...Thankyou.....

0 Kudos
Christos_V
Contributor
Contributor
Jump to solution

I need two more properties to add max value and min value for the desktop pool to report.Is it possible

0 Kudos
Christos_V
Contributor
Contributor
Jump to solution

Get-HVPool | ForEach-Object -Process {
$pool = $_

$summary = Get-HVMachineSummary -PoolName $pool.base.name

New-Object -TypeName PSObject -Property @{

PoolName = $pool.base.name

StationCount = $summary.base.Count

Available = $summary.base.basicstate.Where({$_ -eq 'AVAILABLE'}).Count

Connected = $summary.base.basicstate.Where({$_ -eq 'CONNECTED'}).Count

Disconnected = $summary.base.basicstate.Where({$_ -eq 'DISCONNECTED'}).Count
maxdesktops= $pool.automateddesktopdata.vmnamingsettings.patternnamingsettings.maxnumberofmachines;

}

}

0 Kudos