# StartRDP.msh
# /\/\o\/\/ 2005
# Script to connect to RDP client even if RDP is not enabled
# if RDP was disabled the script will disable RDP again after session.
Function StartRdp {
$MachineName = $Args[0]
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $MachineName)
# $True makes regKey writable
$regKey= $regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Terminal Server" ,$True)
# the Setting is Deny so I reverse it first with ! to set $RDPenabled
$RDPEnabled = !([system.boolean]$regkey.getvalue('fDenyTSConnections'))
write-host "$MachineName RDP = $RDPEnabled"
If (!$RDPEnabled) {
$regkey.SetValue('fDenyTSConnections',0)
#write changes without closing key
$regKey.flush()
write-Host "enabled RDP on $MachineName"
}
sleep 1
"Starting the remote Desktop Connection"
cmd /c mstsc /v: $MachineName
#If changed set the Key back to original value :
if (!$RDPEnabled) {
$regkey.SetValue('fDenyTSConnections',[int]!$RDPEnabled);
write-Host "Disabled RDP again on $MachineName"
}
#Close the Reg Key
$regKey.Close()
}
October 2005 November 2005 December 2005 January 2006 February 2006 March 2006 April 2006 May 2006 June 2006 July 2006 August 2006 September 2006 October 2006 November 2006 December 2006