1. Включаем удаленный рабочий стол с помощью групповых политик GPO.
Computer Configuration > Administrative Templates > Windows Components >Remote Desktop Services > Remote Desktop Session Host > Connections.
1.2 Разрешаем RDP в брандмауэре Windows на удаленном компьютере с Windows 10.
Однако, групповые политики распространяются не так уж быстро, и если вы хотите войти в компьютер "здесь и сейчас" то это способ вам не подходит.
2. Включаем удаленный рабочий стол с помощью Powershell
Однако есть одна загвоздка - на самом деле, две. Брандмауэр Windows может помешать вам, если на компьютере не включено удаленное взаимодействие c PowerShell. Мне известны два способа удаленного включения удаленного рабочего стола через PowerShell. Какой метод вы используете в основном, зависит от конфигурации брандмауэра Windows.
Предположим, что удаленное взаимодействие PowerShell включено на удаленном компьютере. Если это так, вы можете просто включить удаленный рабочий стол, изменив раздел реестра на удаленном компьютере:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Invoke-Command -Computername <computer name> -ScriptBlock {Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" –Value 0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Invoke-Command -Computername <computer name> -ScriptBlock {Enable-NetFirewallRule -DisplayGroup "Remote Desktop"} |
Если удаленное взаимодействие PowerShell не включено на удаленном компьютере, вы все равно можете использовать PowerShell через WMI для этой задачи. Это может быть полезно, если вам нужно включить RDP на нескольких машинах или если эта задача является частью более крупной проблемы автоматизации, а рекомендации по безопасности вашей организации не допускают удаленного взаимодействия PowerShell. Вот сценарий PowerShell, использующий командлет Get-WmiObject, он позволяет удаленно управлять компьютерами без удаленного взаимодействия PowerShell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[cmdletbinding()] | |
param( | |
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] | |
[string[]]$ComputerName = $env:computername, | |
[ValidateScript({Test-Path $_})] | |
[string]$OutFolder = "c:\" | |
) | |
begin { | |
$SuccessComps = Join-Path $OutFolder "Successcomps.txt" | |
$FailedComps = Join-Path $OutFolder "FailedComps.txt" | |
} | |
process { | |
foreach($Computer in $ComputerName) { | |
try { | |
$RDP = Get-WmiObject -Class Win32_TerminalServiceSetting ` | |
-Namespace root\CIMV2\TerminalServices ` | |
-Computer $Computer ` | |
-Authentication 6 ` | |
-ErrorAction Stop | |
} catch { | |
Write-Host "$Computer : WMIQueryFailed" | |
"$Computer : WMIQueryFailed" | Out-File -FilePath $FailedComps -Append | |
continue | |
} | |
if($RDP.AllowTSConnections -eq 1) { | |
Write-Host "$Computer : RDP Already Enabled" | |
"$Computer : RDP Already Enabled" | Out-File -FilePath $SuccessComps -Append | |
continue | |
} else { | |
try { | |
$result = $RDP.SetAllowTsConnections(1,1) | |
if($result.ReturnValue -eq 0) { | |
Write-Host "$Computer : Enabled RDP Successfully" | |
"$Computer : RDP Enabled Successfully" | Out-File -FilePath $SuccessComps -Append | |
} else { | |
Write-Host "$Computer : Failed to enabled RDP" | |
"$Computer : Failed to enable RDP" | Out-File -FilePath $FailedComps -Append | |
} | |
} catch { | |
Write-Host "$computer : Failed to enabled RDP" | |
"$Computer : Failed to enable RDP" | Out-File -FilePath $FailedComps -Append | |
} | |
} | |
} | |
} | |
end {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.\Enable-RDPAccess.ps1 -ComputerName <computer name> |
Если вы хотите включить RDP на нескольких компьютерах с Windows 10, вы можете сохранить имена компьютеров в текстовом файле и затем использовать команделет Get-Content, чтобы передать имена компьютеров в файл Enable-RDPAccess.ps1:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-Content <path to text file> | Enable-RDPAccess.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wmic /node:<computer name> process call create "cmd.exe /c netsh firewall set service RemoteDesktop enable" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wmic /node:<computer name> process call create 'cmd.exe /c reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f' |
Обратите внимание, что необходимо настроить брандмауэр Windows на удаленном компьютере, чтобы разрешить доступ к WMI для сценария PowerShell и для работы wmic.
Вы можете сделать это с помощью групповой политики:
Computer Configuration > Policies > Windows Settings > Security Settings > Windows Firewall with Advanced Security.
4. Включаем удаленный рабочий стол с помощью Psexec
Еще одним вариантом является бесплатный инструмент от Microsoft Psexec. Этот способ также не требует удаленного взаимодействия PowerShell. Единственным недостатком является то, что использовать его не так просто, как Invoke-Command в сценариях PowerShell. Psexec требует, чтобы брандмауэре Windows был открыт порты для общего доступа к файлам и принтерам, что, вероятно, более распространено, чем открытые порты WMI или включенное удаленное взаимодействие с PowerShell:
Computer Configuration > Policies > Administrative Templates > Network > Network Connections > Windows Firewall > Domain Profile > Windows Firewall: Allow inbound file and printer sharing exception
Чтобы изменить реестр для включения RDP с помощью psexec, необходимо выполнить следующую команду:
Чтобы разрешить RDP-подключения в брандмауэре Windows, вы также можете использовать psexec:
Enable Remote Desktop remotely on Windows 10
Еще одним вариантом является бесплатный инструмент от Microsoft Psexec. Этот способ также не требует удаленного взаимодействия PowerShell. Единственным недостатком является то, что использовать его не так просто, как Invoke-Command в сценариях PowerShell. Psexec требует, чтобы брандмауэре Windows был открыт порты для общего доступа к файлам и принтерам, что, вероятно, более распространено, чем открытые порты WMI или включенное удаленное взаимодействие с PowerShell:
Computer Configuration > Policies > Administrative Templates > Network > Network Connections > Windows Firewall > Domain Profile > Windows Firewall: Allow inbound file and printer sharing exception
Чтобы изменить реестр для включения RDP с помощью psexec, необходимо выполнить следующую команду:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
psexec.exe \\<computer name> reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
psexec.exe \\<computer name> netsh firewall set service RemoteDesktop enable |
Enable Remote Desktop remotely on Windows 10
Комментариев нет:
Отправить комментарий