Disable-PSRemoting
Zabrání koncovým bodům PowerShellu přijímat vzdálená připojení.
Syntax
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šší verze 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 Disable-PSRemoting
příkaz 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 tuto 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
ho 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
rutiny. Pokud chcete nastavit konkrétní konfigurace přístupu jednotlivých koncových bodů, použijte rutinu Set-PSSessionConfiguration
spolu s parametrem AccessMode . Další informace o konfiguracích relace 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 u parametru EnableNetworkAccess . 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í rutiny Disable-PSRemoting
. Pokud chcete spustit tuto posloupnost příkazů, spusťte PowerShell s možností Spustit jako správce .
Po zakázání konfigurací New-PSSession
relací se rutina 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í rutin Disable-PSRemoting
a Enable-PSRemoting
rutin.
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. Format-Table
Rutiny Get-PSSessionConfiguration
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 Správa istrators v místním počítači mají povolený přístup ke konfiguracím koncových bodů, pokud se připojují místně (označované 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 povolí 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 popisovače zabezpečení AccessDenied 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
pokusů o vytvoření vzdálené relace k místnímu počítači. Parametr ConfigurationName slouží k zadání 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 chybou Přístup byl odepřen .
Druhé použití New-PSSession
se také pokusí vytvořit vzdálenou relaci k místnímu počítači.
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 naleznete 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 nemá vliv na Disable-PSRemoting
konfigurace koncových bodů Windows PowerShellu. Get-PSSessionConfiguration
Spuštění v prostředí Windows PowerShell zobrazuje 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, Disable-PSRemoting
musí být příkaz spuštěný z relace Windows PowerShellu. Get-PSSessionConfiguration
Spuštění z Prostředí Windows PowerShell teď 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 Disable-PSRemoting
rutina 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 testovací relace. 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í.
Format-Table
Rutiny Get-PSSessionConfiguration
zobrazují konfigurace relací a jejich vlastnosti. Výstup ukazuje, že konfigurace testovací relace umožňuje interaktivní přístup a speciální 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
Get-PSSessionConfiguration
Format-Table
Rutiny teď ukazují, že popisovač zabezpečení AccessDenied pro všechny uživatele sítě se přidá do všech konfigurací relací, včetně konfigurace testovací relace. I když se ostatní popisovače zabezpečení nezmění, přednost má popisovač zabezpečení "network_deny_all". To je znázorněno pokusem o připojení New-PSSession
k konfiguraci testovací relace.
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
se používá ke změně konfigurace relace PowerShell.6 . Parametr AccessMode s hodnotou Remote re-enables remote access to the configuration.
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 zobrazí výzvu k potvrzení.
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Force
Vynutí spuštění příkazu bez výzvy k potvrzení uživatele.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
Zobrazuje, co by se stalo při spuštění rutiny. Rutina není spuštěna.
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | 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 nečiní zpět všechny změny provedené rutinami
Enable-PSRemoting
.Enable-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 Správa istrators 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.
Související odkazy
Váš názor
https://aka.ms/ContentUserFeedback.
Připravujeme: V průběhu roku 2024 budeme postupně vyřazovat problémy z GitHub coby mechanismus zpětné vazby pro obsah a nahrazovat ho novým systémem zpětné vazby. Další informace naleznete v tématu:Odeslat a zobrazit názory pro