Enable-RDP.ps1
Function Enable-RDP { <# .SYNOPSIS Enalbes RDP through Registry in an offline VHD .DESCRIPTION Enalbes RDP through Registry in an offline VHD .EXAMPLE Enable-RDP -Regpath HLKM:NewVM\ Enalbes the RDP-Regsettings on the given Path. The Registry-Structure must be loaded beforehand. .NOTES Version: 1.0 Author: Holger Voges Date: 2018-08-17 www.netz-weise-it.training/weisheiten/ #> [cmdletBinding()] param( [ValidateScript({ Test-Path -Path $_ -PathType Container })] [string] $RegPath, [Bool]$SecureLogonEnabled ) Write-Verbose -Message "Writing RDP Registry Keys" Try { $rdpKey = "$RegPath\ControlSet001\Control\Terminal Server" $FirewallKey = "$RegPath\ControlSet001\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules\" $SecureLogonKey = $rdpKey + '\WinStations\RDP-Tcp' <# Switch ( $SecureLogonEnabled ) { { $SecureLogonEnabled } {set-ItemProperty -Path '$SecureLogonKey' -name 'UserAuthentication' -Value 1 } { -not $SecureLogonEnabled } { set-ItemProperty -Path '$SecureLogonKey' -name 'UserAuthentication' -Value 0 } }#> # set-ItemProperty -Path $rdpKey -name fDenyTSConnections -Value 0 $AllowRDPTcpIn = (Get-ItemProperty -Path $FirewallKey -Name 'RemoteDesktop-UserMode-In-TCP').'RemoteDesktop-UserMode-In-TCP'.Replace('Active=FALSE','Active=TRUE') Set-ItemProperty -Path $FirewallKey -Name 'RemoteDesktop-UserMode-In-TCP' -Value $AllowRDPTcpIn $AllowUDPTcpIn = (Get-ItemProperty -Path $FirewallKey -Name 'RemoteDesktop-UserMode-In-UDP').'RemoteDesktop-UserMode-In-UDP'.Replace('Active=FALSE','Active=TRUE') Set-ItemProperty -Path $FirewallKey -Name 'RemoteDesktop-UserMode-In-UDP' -Value $AllowUDPTcpIn # } Catch { Write-Error -Message "RDP konnte nicht akitivert werden." $_.Exception.ErrorRecord } } |