您的位置:首页 > 运维架构

Enable Remote Desktop via cmdlet?

2016-02-15 14:55 337 查看
from:http://powershell.org/wp/forums/topic/enable-remote-desktop-via-cmdlet/

Hi,

Server 2012 & PowerShell 3.
I simply want to be able to allow remote desktop connections to a server (as done in the GUI via system properties->Remote Tab->Remote Desktop Options).
I have taken a look at the RemoteDesktop Module but cannot see a cmdlet to achieve this?
Is there one? If not any way to achieve via PowerShell?
Thanks,
Nigel.
by mikefrobbins at 2012-12-11 19:56:51

You can enable RDP with PowerShell by using the registry psprovider:

# Allow RDP Connections to this computer
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0

# Require Network Level Authentication
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1

You can use this to allow the firewall exception since you're running PowerShell v3:
# Allow the Remote Desktop firewall exception
Set-NetFirewallRule -DisplayGroup 'Remote Desktop' -Enabled True

Since you're using Server 2012 which means PowerShell remoting is enabled, you can throw all of this in the script block of Invoke-Command to remotely enable RDP:
Invoke-Command -ComputerName 'server1', 'server2' -ScriptBlock {
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server' -Name fDenyTSConnections -Value 0
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1
Set-NetFirewallRule -DisplayGroup 'Remote Desktop' -Enabled True
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  powershell