forked from jagilber/powershellScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rds-ts-disconnect-reasons-all.ps1
71 lines (55 loc) · 1.47 KB
/
rds-ts-disconnect-reasons-all.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# script to return friendly name of rds client hex /decimal error codes
cls
$dupes = new-object Collections.ArrayList
$mstsc = New-Object -ComObject MSTscAx.MsTscAx
$outFile = "c:\temp\clientcodes.txt"
if([IO.File]::Exists($outFile))
{
[IO.File]::Delete($outFile)
}
for($id = 0;$id -lt 100000000;$id++)
{
# 2nd parameter is extended error code
$reason = $($mstsc.GetErrorDescription($id,0))
if($dupes.Contains($reason))
{
continue
}
[void]$dupes.Add($reason)
#weird return
if($reason.Contains("Because of a protocol error"))
{
continue
}
# clean up return
if($reason.Contains("`n"))
{
$reason = $reason.Replace("`n"," ")
}
write-host "$($id)**$($reason)"
out-file -InputObject "$($id)**$($reason)" -FilePath $outFile -Append
}
$dupes.Clear()
for($id = 0;$id -lt 100000000;$id++)
{
# 2nd parameter is extended error code
#$reason = $($mstsc.GetErrorDescription($id,0))
$reason = $($mstsc.GetErrorDescription(0,$id))
if($dupes.Contains($reason))
{
continue
}
[void]$dupes.Add($reason)
#weird return
if($reason.Contains("Because of a protocol error"))
{
continue
}
# clean up return
if($reason.Contains("`n"))
{
$reason = $reason.Replace("`n"," ")
}
write-host "$($id)**Extended Reason:$($reason)"
out-file -InputObject "$($id)**Extended Reason: $($reason)" -FilePath $outFile -Append
}