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 Name | Total | Available | Connected | Disconnected |
Desktop-01 | 10 | 5 | 3 | 2 |
Desktop-02 |
Any help?
Can you try something like this
$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
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
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.
Can you try something like this
$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
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.
Awesome lucd...Works perfectly....
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?
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. | ||||||||||||||||||||||||||||||
|
Hi Jesse,
This vcheck is working and seems highly efficient...Thankyou.....
I need two more properties to add max value and min value for the desktop pool to report.Is it possible
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;
}
}