Disable-PSRemoting
Zabrání koncovým bodům PowerShellu přijímat vzdálená připojení.
Syntaxe
Disable-PSRemoting
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
Tato rutina je dostupná jenom na platformě Windows.
Rutina Disable-PSRemoting
blokuje vzdálený přístup ke všem konfiguracím koncových bodů relace PowerShellu verze 6 a vyšší na místním počítači. Nemá vliv na konfigurace koncových bodů Windows PowerShellu. Pokud chcete zakázat konfigurace koncových bodů relace Windows PowerShellu, spusťte příkaz Disable-PSRemoting
z relace Windows PowerShellu.
Pokud chcete znovu povolit vzdálený přístup ke všem konfiguracím koncových bodů relace PowerShellu verze 6 a vyšší, použijte rutinu Enable-PSRemoting
. Pokud chcete znovu povolit vzdálený přístup ke všem konfiguracím koncových bodů relace Prostředí Windows PowerShell, spusťte Enable-PSRemoting
z relace Prostředí Windows PowerShell.
Poznámka
Pokud chcete zakázat veškerý vzdálený přístup PowerShellu k místnímu počítači s Windows, musíte tento příkaz spustit jak z relace PowerShellu verze 6, tak i z relace Windows PowerShellu. Windows PowerShell je ve výchozím nastavení nainstalovaný na všech počítačích s Windows.
Pokud chcete zakázat a znovu povolit vzdálený přístup ke konkrétním konfiguracím koncových bodů relace, použijte rutiny Enable-PSSessionConfiguration
a Disable-PSSessionConfiguration
. Pokud chcete nastavit konkrétní konfigurace přístupu jednotlivých koncových bodů, použijte rutinu Set-PSSessionConfiguration
společně s parametrem AccessMode. Další informace o konfiguracích relací najdete v tématu about_Session_Configurations.
Poznámka
I po spuštění Disable-PSRemoting
můžete na místním počítači vytvořit připojení zpětné smyčky. Připojení zpětné smyčky je vzdálená relace PowerShellu, která pochází a připojuje se ke stejnému místnímu počítači. Vzdálené relace z externích zdrojů zůstanou blokované. Pro připojení zpětné smyčky musíte použít implicitní přihlašovací údaje podél EnableNetworkAccess parametru. Další informace o připojení zpětné smyčky naleznete v tématu New-PSSession.
Tato rutina je dostupná jenom na platformě Windows. Není k dispozici ve verzích PowerShellu pro Linux nebo macOS. Pokud chcete tuto rutinu spustit, spusťte PowerShell s možností Spustit jako správce.
Příklady
Příklad 1: Zabránění vzdálenému přístupu ke všem konfiguracím relací PowerShellu
Tento příklad brání vzdálenému přístupu ke všem konfiguracím koncových bodů relace PowerShellu v počítači.
Disable-PSRemoting
WARNING: PowerShell remoting has been disabled only for PowerShell 6+ configurations and does not affect
Windows PowerShell remoting configurations. Run this cmdlet in Windows PowerShell to affect all PowerShell
remoting configurations.
WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
1. Stop and disable the WinRM service.
2. Delete the listener that accepts requests on any IP address.
3. Disable the firewall exceptions for WS-Management communications.
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
members of the Administrators group on the computer.
Příklad 2: Zabránění vzdálenému přístupu ke všem konfiguracím relace PowerShellu bez výzvy k potvrzení
Tento příklad zabraňuje vzdálenému přístupu ke všem konfiguracím koncových bodů relace PowerShellu v počítači bez výzvy.
Disable-PSRemoting -Force
WARNING: PowerShell remoting has been disabled only for PowerShell 6+ configurations and does not affect
Windows PowerShell remoting configurations. Run this cmdlet in Windows PowerShell to affect all PowerShell
remoting configurations.
WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
1. Stop and disable the WinRM service.
2. Delete the listener that accepts requests on any IP address.
3. Disable the firewall exceptions for WS-Management communications.
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
members of the Administrators group on the computer.
Příklad 3: Účinky spuštění této rutiny
Tento příklad ukazuje účinek použití Disable-PSRemoting
rutiny. Pokud chcete spustit tuto posloupnost příkazů, spusťte PowerShell s možností Spustit jako správce.
Po zakázání konfigurací relací se rutina New-PSSession
pokusí vytvořit vzdálenou relaci k místnímu počítači (označuje se také jako zpětné smyčky). Vzhledem k tomu, že je na místním počítači zakázaný vzdálený přístup, příkaz selže.
Disable-PSRemoting -Force
New-PSSession -ComputerName localhost -ConfigurationName PowerShell.6
WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
1. Stop and disable the WinRM service.
2. Delete the listener that accepts requests on any IP address.
3. Disable the firewall exceptions for WS-Management communications.
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
members of the Administrators group on the computer.
New-PSSession : [localhost] Connecting to remote server localhost failed with the following error
message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ New-PSSession -ComputerName localhost -ConfigurationName PowerShell.6
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Management.A\u2026tion.RemoteRunspace:RemoteRunspace)
[New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
Příklad 4: Účinky spuštění této rutiny a Enable-PSRemoting
Tento příklad ukazuje vliv na konfigurace relací pomocí Disable-PSRemoting
a rutin Enable-PSRemoting
.
Disable-PSRemoting
slouží k zakázání vzdáleného přístupu ke všem konfiguracím koncových bodů relace PowerShellu. Parametr Force potlačí všechny výzvy uživatele. Rutiny Get-PSSessionConfiguration
a Format-Table
zobrazují konfigurace relací v počítači.
Výstup ukazuje, že všichni vzdálení uživatelé s tokenem sítě mají odepřený přístup ke konfiguracím koncových bodů. Skupina Administrators v místním počítači má povolený přístup ke konfiguracím koncových bodů, pokud se připojují místně (označuje se také jako zpětné smyčky) a používají implicitní přihlašovací údaje.
Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize
Enable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize
Name Permission
---- ----------
PowerShell.6 NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed ...
PowerShell.6.2.0 NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed ...
Name Permission
---- ----------
PowerShell.6 NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed ...
PowerShell.6.2.0 NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed ...
Rutina Enable-PSRemoting
znovu umožňuje vzdálený přístup ke všem konfiguracím koncových bodů relace PowerShellu v počítači. Parametr Force potlačí všechny výzvy uživatele a restartuje službu WinRM bez výzvy. Nový výstup ukazuje, že AccessDenied popisovače zabezpečení byly odebrány ze všech konfigurací relací.
Příklad 5: Připojení zpětné smyčky se zakázanými konfiguracemi koncových bodů relace
Tento příklad ukazuje, jak jsou konfigurace koncových bodů zakázány, a ukazuje, jak provést úspěšné připojení zpětné smyčky ke zakázanému koncovému bodu.
Disable-PSRemoting
zakáže všechny konfigurace koncových bodů relace PowerShellu.
Disable-PSRemoting -Force
WARNING: PowerShell remoting has been disabled only for PowerShell 6+ configurations and does not affect
Windows PowerShell remoting configurations. Run this cmdlet in Windows PowerShell to affect all PowerShell
remoting configurations.
WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
1. Stop and disable the WinRM service.
2. Delete the listener that accepts requests on any IP address.
3. Disable the firewall exceptions for WS-Management communications.
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
members of the Administrators group on the computer.
New-PSSession -ComputerName localhost -ConfigurationName powershell.6 -Credential (Get-Credential)
PowerShell credential request
Enter your credentials.
User: UserName
Password for user UserName: ************
New-PSSession: [localhost] Connecting to remote server localhost failed with the following error message
: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
New-PSSession -ComputerName localhost -ConfigurationName powershell.6 -EnableNetworkAccess
Id Name Transport ComputerName ComputerType State ConfigurationName Availability
-- ---- --------- ------------ ------------ ----- ----------------- ------------
1 Runspace1 WSMan localhost RemoteMachine Opened powershell.6 Available
První použití New-PSSession
se pokusí vytvořit vzdálenou relaci místního počítače. Parametr ConfigurationName slouží k určení zakázaného koncového bodu PowerShellu. Přihlašovací údaje se do příkazu explicitně předávají prostřednictvím parametru credential. Tento typ připojení prochází zásobníkem sítě a nejedná se o zpětné smyčky. V důsledku toho pokus o připojení k zakázanému koncovému bodu selže s Access je odepřen chybě.
Druhé použití New-PSSession
se také pokusí vytvořit vzdálenou relaci místního počítače.
V tomto případě je úspěšné, protože se jedná o připojení zpětné smyčky, které obchází zásobník sítě.
Při splnění následujících podmínek se vytvoří připojení zpětné smyčky:
- Název počítače, ke kterému se chcete připojit, je localhost.
- Nejsou předány žádné přihlašovací údaje. Aktuální přihlášený uživatel (implicitní přihlašovací údaje) se používá pro připojení.
- Použije se parametr přepínače EnableNetworkAccess.
Další informace o připojeních zpětné smyčky najdete v dokumentu New-PSSession.
Příklad 6: Zakázání všech konfigurací vzdálené komunikace PowerShellu
Tento příklad ukazuje, jak spuštění příkazu Disable-PSRemoting
nemá vliv na konfigurace koncových bodů Windows PowerShellu.
Get-PSSessionConfiguration
spustit v prostředí Windows PowerShell zobrazí všechny konfigurace koncových bodů. Vidíme, že konfigurace koncových bodů Windows PowerShellu nejsou zakázané.
Disable-PSRemoting -Force
powershell.exe -command 'Get-PSSessionConfiguration'
WARNING: PowerShell remoting has been disabled only for PowerShell 6+ configurations and does not affect
Windows PowerShell remoting configurations. Run this cmdlet in Windows PowerShell to affect all PowerShell
remoting configurations.
WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
1. Stop and disable the WinRM service.
2. Delete the listener that accepts requests on any IP address.
3. Disable the firewall exceptions for WS-Management communications.
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
members of the Administrators group on the computer.
Name : microsoft.powershell
PSVersion : 5.1
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed, BUILTIN\Remote
Management Users AccessAllowed
Name : microsoft.powershell.workflow
PSVersion : 5.1
StartupScript :
RunAsUser :
Permission : BUILTIN\Administrators AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
Name : microsoft.powershell32
PSVersion : 5.1
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed, BUILTIN\Remote
Management Users AccessAllowed
Name : PowerShell.6
PSVersion : 6.2
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators
AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
Name : PowerShell.6.2.2
PSVersion : 6.2
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators
AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
powershell.exe -command 'Disable-PSRemoting -Force'
powershell.exe -command 'Get-PSSessionConfiguration'
WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting or
Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
1. Stop and disable the WinRM service.
2. Delete the listener that accepts requests on any IP address.
3. Disable the firewall exceptions for WS-Management communications.
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to members of the
Administrators group on the computer.
Name : microsoft.powershell
PSVersion : 5.1
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators
AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
Name : microsoft.powershell.workflow
PSVersion : 5.1
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed, BUILTIN\Remote Management
Users AccessAllowed
Name : microsoft.powershell32
PSVersion : 5.1
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators
AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
Name : PowerShell.6
PSVersion : 6.2
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators
AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
Name : PowerShell.6.2.2
PSVersion : 6.2
StartupScript :
RunAsUser :
Permission : NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators
AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
Pokud chcete tyto konfigurace koncových bodů zakázat, musí se příkaz Disable-PSRemoting
spustit z relace Windows PowerShellu. Teď Get-PSSessionConfiguration
spustit v prostředí Windows PowerShell ukazuje, že jsou zakázány všechny konfigurace koncových bodů.
Příklad 7: Zabránění vzdálenému přístupu ke konfiguracím relací, které mají vlastní popisovače zabezpečení
Tento příklad ukazuje, že rutina Disable-PSRemoting
zakáže vzdálený přístup ke všem konfiguracím relací, které zahrnují konfigurace relací s vlastními popisovači zabezpečení.
Register-PSSessionConfiguration
vytvoří konfiguraci relace Test. Parametr FilePath určuje konfigurační soubor relace, který relaci přizpůsobí. Parametr ShowSecurityDescriptorUI zobrazí dialogové okno, které nastaví oprávnění pro konfiguraci relace. V dialogovém okně Oprávnění vytvoříme pro uvedeného uživatele vlastní úplná přístupová oprávnění.
Rutiny Get-PSSessionConfiguration
a Format-Table
zobrazují konfigurace relací a jejich vlastnosti. Výstup ukazuje, že konfigurace relace Test umožňuje interaktivní přístup a zvláštní oprávnění pro daného uživatele.
Disable-PSRemoting
zakáže vzdálený přístup ke všem konfiguracím relací.
Register-PSSessionConfiguration -Name Test -FilePath .\TestEndpoint.pssc -ShowSecurityDescriptorUI -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Wrap
Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Wrap
New-PSSession -ComputerName localhost -ConfigurationName Test
Name Permission
---- ----------
PowerShell.6 NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed,
BUILTIN\Remote Management Users AccessAllowed
PowerShell.6.2.0 NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed,
BUILTIN\Remote Management Users AccessAllowed
Test NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed,
User01 AccessAllowed
WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
1. Stop and disable the WinRM service.
2. Delete the listener that accepts requests on any IP address.
3. Disable the firewall exceptions for WS-Management communications.
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
members of the Administrators group on the computer.
Name Permission
---- ----------
PowerShell.6 NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed,
BUILTIN\Administrators AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
PowerShell.6.2.0 NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed,
BUILTIN\Administrators AccessAllowed, BUILTIN\Remote Management Users AccessAllowed
Test NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed,
BUILTIN\Administrators AccessAllowed, User01 AccessAllowed
New-PSSession : [localhost] Connecting to remote server localhost failed with the following error message
: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ New-PSSession -ComputerName localhost -ConfigurationName Test
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Management.A\u2026tion.RemoteRunspace:RemoteRunspace)
[New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
Teď rutiny Get-PSSessionConfiguration
a Format-Table
ukazují, že popisovač zabezpečení AccessDenied pro všechny uživatele sítě se přidá do všech konfigurací relací, včetně konfigurace relace Test. I když se ostatní popisovače zabezpečení nezmění, přednost má popisovač zabezpečení "network_deny_all". Ukazuje to pokus o použití New-PSSession
pro připojení ke konfiguraci relace Test.
Příklad 8: Opětovné povolení vzdáleného přístupu k vybraným konfiguracím relací
Tento příklad ukazuje, jak znovu povolit vzdálený přístup pouze k vybraným konfiguracím relací. Po zakázání všech konfigurací relací znovu povolíme konkrétní relaci.
Rutina Set-PSSessionConfiguration
slouží ke změně konfigurace relace PowerShell.6. Parametr AccessMode s hodnotou Vzdálené znovu povolí vzdálený přístup ke konfiguraci.
Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize
Set-PSSessionConfiguration -Name PowerShell.6 -AccessMode Remote -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize
WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting
or Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps:
1. Stop and disable the WinRM service.
2. Delete the listener that accepts requests on any IP address.
3. Disable the firewall exceptions for WS-Management communications.
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to
members of the Administrators group on the computer.
Name Permission
---- ----------
PowerShell.6 NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Adm ...
PowerShell.6.2.0 NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Adm ...
Name Permission
---- ----------
PowerShell.6 NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed, BUILTIN\ ...
PowerShell.6.2.0 NT AUTHORITY\NETWORK AccessDenied, NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Adm ...
Parametry
-Confirm
Před spuštěním rutiny vás vyzve k potvrzení.
Typ: | SwitchParameter |
Aliasy: | cf |
Position: | Named |
Default value: | False |
Vyžadováno: | False |
Přijmout vstup kanálu: | False |
Přijmout zástupné znaky: | False |
-Force
Vynutí spuštění příkazu bez výzvy k potvrzení uživatele.
Typ: | SwitchParameter |
Position: | Named |
Default value: | None |
Vyžadováno: | False |
Přijmout vstup kanálu: | False |
Přijmout zástupné znaky: | False |
-WhatIf
Ukazuje, co se stane, když se rutina spustí. Rutina se nespustí.
Typ: | SwitchParameter |
Aliasy: | wi |
Position: | Named |
Default value: | False |
Vyžadováno: | False |
Přijmout vstup kanálu: | False |
Přijmout zástupné znaky: | False |
Vstupy
None
Do této rutiny nemůžete roušit objekty.
Výstupy
None
Tato rutina nevrátí žádný výstup.
Poznámky
Tato rutina je dostupná jenom na platformách Windows.
Zakázání konfigurací relace neruší všechny změny provedené
Enable-PSRemoting
nebo rutinamiEnable-PSSessionConfiguration
. Možná budete muset následující změny vrátit zpět ručně.- Zastavte a zakažte službu WinRM.
- Odstraňte naslouchací proces, který přijímá požadavky na libovolnou IP adresu.
- Zakažte výjimky brány firewall pro komunikaci WS-Management.
- Obnovte hodnotu LocalAccountTokenFilterPolicy na hodnotu 0, která omezuje vzdálený přístup na členy skupiny Administrators v počítači.
Konfigurace koncového bodu relace je skupina nastavení, která definují prostředí pro relaci. Každá relace, která se připojuje k počítači, musí používat jednu z konfigurací koncových bodů relace zaregistrovaných v počítači. Odepřením vzdáleného přístupu ke všem konfiguracím koncových bodů relace efektivně zabráníte vzdáleným uživatelům navazovat relace, které se připojují k počítači.