Enable-RDPRemotelyWMI.ps1
19 Sep 2025Description
Enable-RDPRemotelyWMI
provides a WMI-based option for enabling Remote Desktop on remote Windows systems. It queries the Win32_TerminalServiceSetting
class over DCOM and executes SetAllowTSConnections(1,1)
so that both RDP and the firewall exception are activated.
Usage examples
Enable-RDPRemotelyWMI -ComputerName 'legacy01'
'server01','server02' | Enable-RDPRemotelyWMI
Leverage this helper when CIM/WSMan is unavailable but you can still reach the host using classic WMI remoting.
Script
function Enable-RDPRemotelyWMI {
# You can enable RDP on a remote host by simply running the below two lines.
[CmdletBinding()]
param (
[Parameter()]
[string[]]
$ComputerName
)
foreach ($Computer in $ComputerName) {
$tsobj = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace Root\CimV2\TerminalServices -ComputerName $Computer
$tsobj.SetAllowTSConnections(1, 1)
}
}
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.