Remotely Enable RDP with PowerShell

Hunting around online for interesting things to learn in powershell I found this link . The first code only works on XP but if you read on there is a version that works both with Vista and XP. I modified this and put security to default 0 to make it an easier command to remember in the future. I also changed the name to RDPon for my own purposes and set a write-host command at the end of the function so I know it really ran.

Just run the script in powershell, then reference the function like the example below. Thanks Pete Gomersall!!!!

Example:
rdpon computer 1

RDPon.ps1


Function RDPon ($Server, $Set)
{
$OS = gwmi Win32_OperatingSystem -Computer $Server
If ($OS.BuildNumber -ge 6000){
$Terminal = gwmi -namespace "root\CIMV2\TerminalServices" Win32_TerminalServiceSetting –Computer $Server
$SetSecure = gwmi -namespace "root\CIMV2\TerminalServices" Win32_TSGeneralSetting –Computer $Server
$Terminal.SetAllowTSConnections($Set)
$SetSecure.SetUserAuthenticationRequired(0)
}
Else {
$Terminal = gwmi Win32_TerminalServiceSetting –Computer $Server
$SetSecure = gwmi Win32_TSGeneralSetting –Computer $Server
$Terminal.SetAllowTSConnections($Set)
}
}
write-host RDPon Enabled!