I had a teammate request that I enable Remote Desktop for Administration as a portion of my SCVMM Service Template.
You cannot script sconfig – although that is a easy manual way to do it.
If you try any of the Server 2012 cmdlets you will end up mucking with Remote Desktop Services and enabling user access.
Well, it turns out the key is a key. And it is easiest to tweak it with WMI.
The following script runs on the server that is being modified (localhost is the default). And it can run using administrator or local system security credentials.
try {
$RDP = Get-WmiObject -Class Win32_TerminalServiceSetting `
-Namespace root\CIMV2\TerminalServices
# -Computer $Computer `
# -Authentication 6 `
# -ErrorAction Stop
} catch {
"WMIQueryFailed"
continue
}
if($RDP.AllowTSConnections -eq 1) {
"RDP Already Enabled"
continue
} else {
try {
$result = $RDP.SetAllowTsConnections(1,1)
if($result.ReturnValue -eq 0) { "Enabled RDP Successfully" }
if ($result.ReturnValue -eq 4096) {
$Job = [WMI]$Result.Job
while ($Job.JobState -eq 4) {
Write-Progress -Id 2 -ParentId 1 $Job.Caption -Status "Executing" -PercentComplete $Job.PercentComplete
Start-Sleep 1
$Job.PSBase.Get()
}
}
} catch {
"Failed to enable RDP"
}
}