Import-Module remotedesktop
$GetName = Read-Host -Prompt 'What user are you looking for?'
$sessions = Get-RDUserSession -ConnectionBroker RDS-bgw.ais.domain
Write-Host -ForegroundColor Yellow "Sessions for" $GetName
$GetName = $sessions | ? {$_.Username -eq $GetName}
if ($GetName -eq $null) {
Write-Host "No Terminal Sessions found for" $GetName
}
elseif ($GetName -ne $null) {
$GetName
}
if ($kill -eq $true) {
Write-Host -ForegroundColor Yellow "Kill switch specificed...Logging off above sessions"
$GetName | % {Invoke-RDUserLogoff -HostServer $_.HostServer -UnifiedSessionID $_.UnifiedSessionId -Force}
}