squardothegreat
12/31/2018 - 6:35 PM

Find-TermUser.ps1

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}
    }