Last active
September 29, 2020 07:56
-
-
Save lansalot/a8e4addeb4043b96c9acade3dcbe2871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[OutputType("PSAzureOperationResponse")] | |
$LogAnalyticsWorkspaceId = "<as it sounds>" | |
$LogAnalyticsPrimaryKey = "<primary key>" | |
$HostPool = "<name of host pool>" | |
$RGName = "<resource group host pool is in>" | |
$connection = Get-AutomationConnection -Name AzureRunAsConnection | |
[void](Connect-AzAccount ` | |
-ServicePrincipal ` | |
-Tenant $connection.TenantID ` | |
-ApplicationId $connection.ApplicationID ` | |
-CertificateThumbprint $connection.CertificateThumbprint) | |
Try { | |
$ActiveSessions = (Get-AzWvdUserSession -HostPoolName $HostPool -ResourceGroupName $RGName | Where {$_.SessionState -eq 'Active'}).Count | |
$DisconnectedSessions = (Get-AzWvdUserSession -HostPoolName $HostPool -ResourceGroupName $RGName | Where {$_.SessionState -eq 'Disconnected'}).Count | |
Write-Output "Logging $($ActiveSessions) active sessions and $($DisconnectedSessions) disconnected sessions" | |
$body_obj = @{ | |
'hostpoolName' = $HostPool | |
'ActiveSessions' = $ActiveSessions | |
'DisconnectedSessions' = $DisconnectedSessions | |
} | |
$json_body = ConvertTo-Json -Compress $body_obj | |
Send-OMSAPIIngestionFile -customerId $LogAnalyticsWorkspaceId -sharedKey $LogAnalyticsPrimaryKey -Body $json_body -logType 'WVDSessions_CL' | |
} catch { | |
Write-Output "Error in script" | |
$_ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment