Microsoft Exchange, Powershell, AD, MOM...

14 Kasım 2007 Çarşamba

Enable RDP from a Remote Location with PowerShell

RDP is enabled or disabled through a Registry key (to be honest mostly System properties GUI is used!!) But what if there is no way of being physically near the computer that you want to rdp. In such a senario System properties GUI is useless as there is no way to reach it. But a simple PowerShell script can make it happen for you. Since PowerShell standart cmdlets don't allow you to change a remote registry value directly, we called a class from .NET for it. The registry key to enable RDP is HKLM:\\System\CurrentControlSet\Control\Terminal Server\fDentTSConnections

Just copy-paste the code below to notepad save as with ps1 extension (i gave the name Get-Rdp.ps1)

$computer=$args
$reg=[microsoft.win32.registrykey]::openremotebasekey('localmachine',$computer)
$regkey=$reg.opensubkey("system\\currentcontrolset\\control\\terminal server",$true)
$regterminal=[system.boolean]$regkey.getvalue('fdenytsconnections')
write-host $computer RDP-> (!$regterminal)

if($regterminal)
{
$choice = read-host "RDP is disabled. Do u want to enable it?[Y/N]"
if($choice = "y")
{
$regkey.setvalue('fdenytsconnections',0)
}
}
write-host RDP enabled (![system.boolean]$regkey.getvalue('fdenytsconnections'))



Below you may see how it works!!

PS C:\ps> .\Get-Rdp.ps1 10.4.62.90
10.4.62.90 RDP-> False
RDP is disabled. Do u want to enable it?[Y/N]: y
RDP enabled True

Hiç yorum yok: