PowerShell: Enable Remote Desktop

function enableRemoteDesktop{
    Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name 'fDenyTSConnections' -value 0
    Enable-NetFirewallRule -DisplayGroup 'Remote Desktop'
}

function disableRemoteDesktop{
    Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name 'fDenyTSConnections' -value 1
    Disable-NetFirewallRule -DisplayGroup 'Remote Desktop'
}

invoke-command -computername 'server4158194158971847109571384791' -ScriptBlock{
    param($enableShits)
    [ScriptBlock]::Create($enableShits).invoke()
    } -Args ${function:enableRemoteDesktop}

Leave a Reply

Your email address will not be published. Required fields are marked *