Hi guys,
I am trying to make a script with two requirements
1) Get the count of total , available , connected and disconnected sessions of single desktop pool.
2) Get the usernames and duration of the connected session in that desktop pool.
Am done with first point and dont know how to do with the second.
Here is what I did:
$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}
$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 "Diconnected Systems in the pool are:" $Disconnected
#End
Any Help?
Does Wouter's Pulling horizon session information using PowerCLI post help?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thanks for the reply...
Below script is giving my required output. But it gives the connected users of all the desktop pools, how to fetch it for a single desktop pool?
$query = New-Object "Vmware.Hv.QueryDefinition"
$query.queryEntityType = 'SessionLocalSummaryView'
$qSrv = New-Object "Vmware.Hv.QueryServiceService"
$qSRv.QueryService_Query($global:DefaultHVServers[0].ExtensionData,$query).Results |
Select @{Name="User Name";Expression={$_.NamesData.UserName.Replace("mydomain\","")}}, @{Name="State";Expression={$_.SessionData.SessionState}}, @{Name="Initial Connection Time";Expression={$_.SessionData.StartTime}} | Where {$_.State -eq "Connected"} |
Sort "User Name" |
Select "User Name", "Initial Connection Time"
Hi LucD,
As for now I had used Where clause for my requirement and its working fine.
Where {$_.DName -eq "$pool"}
Here is the complete script.
$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}
$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
start-sleep -s 2
$query = New-Object "Vmware.Hv.QueryDefinition"
$query.queryEntityType = 'SessionLocalSummaryView'
$qSrv = New-Object "Vmware.Hv.QueryServiceService"
$qSRv.QueryService_Query($global:DefaultHVServers[0].ExtensionData,$query).Results |
Select @{Name="User Name";Expression={$_.NamesData.UserName.Replace("mydomain\","")}}, @{Name="DName";Expression={$_.NamesData.DesktopName}}, @{Name="State";Expression={$_.SessionData.SessionState}}, @{Name="Initial Connection Time";Expression={$_.SessionData.StartTime}} | Where {$_.State -eq "Connected" -and $_.DName -eq "$pool"} |
Sort "User Name" |
Select "User Name", "Initial Connection Time"
##End