$ConnectionBroker = "srv-ts-04.fc-moron.ru"
$AllSessions = Get-RDUserSession -ConnectionBroker $ConnectionBroker
if($AllSessions -eq $null){
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$Title = "Просмотр терминальных сессий"
$Message = "Не найдено ни одной сессии"
$Buttons = [System.Windows.Forms.MessageBoxButtons]::OK
$Icon = [System.Windows.Forms.MessageBoxIcon]::Exclamation
[System.Windows.Forms.MessageBox]::Show($Message,$Title,$Buttons,$Icon)
return
}
$ActiveSessions = $AllSessions | Where-Object -Property SessionState -EQ "STATE_ACTIVE"
$GridView = $ActiveSessions | Select-Object -Property CollectionName,UserName,CreateTime,HostServer,SessionID
$Session = $GridView | Out-GridView -Title "Просмотр терминальных сессий" -OutputMode Single
if($Session -eq $null){
# No session selected, user probably clicked Cancel
return
}
mstsc /v:($Session.HostServer) /shadow:($Session.SessionId) /noConsentPrompt| Out-Null