Created
February 13, 2011 22:40
-
-
Save jstangroome/825240 to your computer and use it in GitHub Desktop.
Basic PowerShell wrapper around command-line tools for querying and reseting Terminal Services sessions.
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 Get-TSSession { | |
& query session | | |
Select-Object -Skip 1 | | |
ForEach-Object { | |
if ($_ -match '^(?<this>.)(?<sessionname>.{18})(?<username>.{22})(?<id>.{6})(?<state>.{8})(?<type>.{8})(?<device>.*)') { | |
New-Object -TypeName PSObject -Property @{ | |
SessionName = $Matches.sessionname.TrimEnd() | |
UserName = $Matches.username.TrimEnd() | |
SessionId = [int]::Parse($Matches.id) | |
State = $Matches.state.Trim() | |
Type = $Matches.type.TrimEnd() | |
Device = $Matches.device.TrimEnd() | |
Current = $Matches.this -ne ' ' | |
} | |
} | |
} | |
} | |
function Remove-TSSession ( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] | |
[int] | |
$SessionId | |
) { | |
'y' | & reset session $SessionId | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment