Enable-RDPRemotelyCIM.ps1


Description

Use Enable-RDPRemotelyCIM to turn on Remote Desktop across one or more systems via the CIM Win32_TerminalServiceSetting class. The function enables both the service and the firewall exception by calling SetAllowTSConnections with AllowTSConnections=1 and ModifyFirewallException=1 for each computer supplied.

Usage examples

Enable-RDPRemotelyCIM -ComputerName 'host01'
Import-Csv .\servers.csv | Select-Object -ExpandProperty Name | Enable-RDPRemotelyCIM

Run the script from an elevated session that has network access and appropriate permissions to configure the remote hosts.


Script

function Enable-RDPRemotelyCIM {
    # You can enable RDP on a remote host by simply running the below two lines.
    [CmdletBinding()]
    param (
        [Parameter()]
        [string[]]
        $ComputerName
    )

    foreach ($Computer in $ComputerName) {
        $Win32TerminalServiceSettings = Get-CimInstance -Namespace root/cimv2/TerminalServices -ClassName Win32_TerminalServiceSetting -ComputerName $Computer
        $Win32TerminalServiceSettings | Invoke-CimMethod -MethodName SetAllowTSConnections -Arguments @{AllowTSConnections=1;ModifyFirewallException=1} -ComputerName $Computer
    }

}

Back to Top


Download

Please feel free to copy parts of the script or if you would like to download the entire script, simple 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