-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnable-RDPAccess.ps1
55 lines (46 loc) · 1.86 KB
/
Enable-RDPAccess.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
[cmdletbinding()]
param(
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = $env:computername,
[ValidateScript({Test-Path $_})]
[string]$OutFolder = "c:\"
)
begin {
$SuccessComps = Join-Path $OutFolder "Successcomps.txt"
$FailedComps = Join-Path $OutFolder "FailedComps.txt"
}
process {
foreach($Computer in $ComputerName) {
try {
$RDP = Get-WmiObject -Class Win32_TerminalServiceSetting `
-Namespace root\CIMV2\TerminalServices `
-Computer $Computer `
-Authentication 6 `
-ErrorAction Stop
} catch {
Write-Host "$Computer : WMIQueryFailed"
"$Computer : WMIQueryFailed" | Out-File -FilePath $FailedComps -Append
continue
}
if($RDP.AllowTSConnections -eq 1) {
Write-Host "$Computer : RDP Already Enabled"
"$Computer : RDP Already Enabled" | Out-File -FilePath $SuccessComps -Append
continue
} else {
try {
$result = $RDP.SetAllowTsConnections(1,1)
if($result.ReturnValue -eq 0) {
Write-Host "$Computer : Enabled RDP Successfully"
"$Computer : RDP Enabled Successfully" | Out-File -FilePath $SuccessComps -Append
} else {
Write-Host "$Computer : Failed to enabled RDP"
"$Computer : Failed to enable RDP" | Out-File -FilePath $FailedComps -Append
}
} catch {
Write-Host "$computer : Failed to enabled RDP"
"$Computer : Failed to enable RDP" | Out-File -FilePath $FailedComps -Append
}
}
}
}
end {}