PowerShell:在多个服务器上远程启用远程桌面(批量)
在本文中,我将展示如何使用 Windows PowerShell 在 Active Directory 环境中的多个服务器系统上激活远程桌面。在大型环境中,可能需要在大量计算机上启用远程桌面。本文将帮助您节省时间。
获取您的服务器列表
首先,我们必须检索目标系统的列表。登录到您的域控制器之一。要将域中所有服务器系统(成员服务器 + 域控制器)的名称保存到文件中,请运行
(Get-ADComputer -Filter 'operatingsystem -like "*server*"').Name | Out-File C:\Temp\Servers.txt完成后,请仔细检查您的清单。
远程激活多个服务器系统上的远程桌面
现在我们做主。运行以下代码,在列表中的所有服务器上激活 RD,并为远程桌面组配置 Windows 防火墙例外。
Get-Content C:\Temp\Servers.txt | ForEach-Object {Invoke-Command -ComputerName $_ {Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-Name "fDenyTSConnections" -Value 0;Enable-NetFirewallRule -DisplayGro
up "Remote Desktop"}}检查您的设置
在其中一台服务器上打开服务器管理器并检查远程桌面的状态。
接下来,运行以下命令检查所有远程桌面防火墙规则。
Get-NetFirewallRule -DisplayGroup "Remote Desktop" | Select-Object DisplayName,Enabled,Profile,Direction,Action好一个。
要通过组策略启用远程桌面,请参阅此文章:
https://social.technet.microsoft.com/wiki/contents/articles/4980.how-to-enable-or-disable-remote-desktop-via-group-policy-windows-2008.aspx




