Set-RDPStatus.ps1


Description

Purpose

Enables or disables RDP on specified computers.

Detailed Description

Configures the RDP settings on specified computers using CIM/WMI methods.

Back to Top

Usage

Example 1

Set-RDPStatus -ComputerName "DANTOOINE" -Enable

Example 2

Set-RDPStatus -ComputerName "DANTOOINE"

Back to Top

Notes

No additional notes.

Back to Top


Script

# Function: Set-RDPStatus
Function Set-RDPStatus {
    <#
    .SYNOPSIS
    Enables or disables RDP on specified computers.

    .DESCRIPTION
    Configures the RDP settings on specified computers using CIM/WMI methods.

    .PARAMETER ComputerName
    Name or IP address of the computer(s) to configure.

    .PARAMETER Enable
    Switch to enable RDP. If not specified, RDP will be disabled.

    .EXAMPLE
    Set-RDPStatus -ComputerName "DANTOOINE" -Enable

    .EXAMPLE
    Set-RDPStatus -ComputerName "DANTOOINE"
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string[]]$ComputerName,

        [Parameter(Mandatory = $false)]
        [switch]$Enable
    )

    foreach ($Computer in $ComputerName) {
        try {
            $Settings = Get-CimInstance -Namespace root/cimv2/TerminalServices -ClassName Win32_TerminalServiceSetting -ComputerName $Computer
            $Settings | Invoke-CimMethod -MethodName SetAllowTSConnections -Arguments @{ AllowTSConnections = [int]$Enable; ModifyFirewallException = [int]$Enable } -ComputerName $Computer
            Write-Output "$($Computer): RDP $($Enable ? 'enabled' : 'disabled')."
        } catch {
            Write-Warning "Failed to set RDP status on $($Computer): $_"
        }
    }
}

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top