Last active
June 8, 2016 09:35
-
-
Save rossnz/72af1c5d2ced025b8ffa264bf0f10cac to your computer and use it in GitHub Desktop.
Log yourself off from old TS / RDP sessions. Remote computer name can be passed as a parameter, or on the pipeline. Useful if you have to log out of a lot of machines :)
This file contains hidden or 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
function Exit-TsSession { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$True, | |
ValueFromPipeline=$True)] | |
[string[]]$computername | |
) | |
begin { | |
$username = $env:USERNAME | |
} | |
process { | |
Write-Verbose "Computername: $computername" | |
Write-Verbose "Username: $username" | |
$session = ((quser /server:$computername | ? { $_ -match $username }) -split ' +')[2] | |
Write-Verbose "Session: $session" | |
Write-Verbose "Logging $username off from $computername..." | |
logoff $session /server:$computername | |
Write-Verbose "Done!" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment