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
# Require Network Level Authentication
You can use this to allow the firewall exception since you're running PowerShell v3:
# Allow the Remote Desktop firewall exception
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:
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打开或关闭光驱
- PowerShell移动目录中指定文件的方法(非全部文件)
- Powershell小技巧之创建短网址
- PowerShell实现查询打开某个文件的默认应用程序
- PowerShell设置文件只读、隐藏属性的方法
- Windows Powershell扩展类型系统
- PowerShell脚本源码输出到文件的最佳写法
- Windows Powershell 通过函数扩展别名
- PowerShell脚本实现创建桌面快捷方式的方法
- PowerShell重启服务命令Restart-Service详细介绍
- PowerShell中执行Javascript的方法示例
- 探索PowerShell(十三) WMI对象介绍
- Powershell小技巧之使用Copy-Item添加程序到开机启动
- Windows Powershell创建对象
- Windows Powershell 访问数组
- Powershell小技巧之使用WS-Man来调用PowerShell命令
- PowerShell在控制台输出特殊符号的方法
- Windows Powershell使用哈希表
- PowerShell实现的文件同步脚本分享
- PowerShell中使用通配符匹配文件路径的例子