Skip to content

Commit 75c6901

Browse files
committed
Add support for whatif
1 parent 0e9cef7 commit 75c6901

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

TOOL-Set-RDPDisable/Set-RDPDisable.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,22 @@ function Set-RDPDisable {
2323
lazywinadmin.com
2424
@lazywinadmin
2525
#>
26-
[CmdletBinding()]
26+
[CmdletBinding(SupportsShouldProcess = $true)]
2727
PARAM (
2828
[String[]]$ComputerName = $env:COMPUTERNAME
2929
)
3030
PROCESS {
3131
FOREACH ($Computer in $ComputerName) {
3232
TRY {
33-
IF (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
34-
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $Computer)
35-
$regKey = $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server", $True)
36-
$regkey.SetValue("fDenyTSConnections", 1)
37-
$regKey.flush()
38-
$regKey.Close()
39-
} #IF Test-Connection
33+
IF ($PSCmdlet.ShouldProcess($Computer, "Disable Remote Desktop")) {
34+
IF (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
35+
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $Computer)
36+
$regKey = $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server", $True)
37+
$regkey.SetValue("fDenyTSConnections", 1)
38+
$regKey.flush()
39+
$regKey.Close()
40+
} #IF Test-Connection
41+
}
4042
} #Try
4143
CATCH {
4244
$PSCmdlet.ThrowTerminatingError($_)

0 commit comments

Comments
 (0)