functions/Disable-RDP.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<#
.SYNOPSIS
    Disable Remote Desktop remotely
.EXAMPLE
    Disable-RDP -ComputerName test-1
#>

function Disable-RDP {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string[]]$ComputerName
    )

    process {
        Invoke-Command -ComputerName $ComputerName -ScriptBlock {
        Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -Name 'fDenyTSConnections' -Value 1
        Netsh advfirewall firewall set rule group='remote desktop' new enable=no
        }
    }
}