Disable-PSRemoting

Förhindrar att PowerShell-slutpunkter tar emot fjärranslutningar.

Syntax

Disable-PSRemoting
       [-Force]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]

Description

Den här cmdleten är endast tillgänglig på Windows-plattformen.

Cmdleten Disable-PSRemoting blockerar fjärråtkomst till alla PowerShell version 6 och större sessionsslutpunktskonfigurationer på den lokala datorn. Det påverkar inte Windows PowerShell-slutpunktskonfigurationer. Om du vill inaktivera windows PowerShell-sessionsslutpunktskonfigurationer kör du Disable-PSRemoting kommandot inifrån en Windows PowerShell-session.

Om du vill återaktivera fjärråtkomst till alla PowerShell version 6- och senare sessionsslutpunktskonfigurationer använder du cmdleten Enable-PSRemoting . Om du vill återaktivera fjärråtkomst till alla Windows PowerShell-sessionsslutpunktskonfigurationer kör Enable-PSRemoting du inifrån en Windows PowerShell-session.

Kommentar

Om du vill inaktivera all PowerShell-fjärråtkomst till en lokal Windows-dator måste du köra det här kommandot både från en session i PowerShell version 6 eller senare och inifrån en Windows PowerShell-session. Windows PowerShell är installerat på alla Windows-datorer som standard.

Om du vill inaktivera och återaktivera fjärråtkomst till specifika sessionsslutpunktskonfigurationer använder du Enable-PSSessionConfiguration cmdletarna och Disable-PSSessionConfiguration . Om du vill ange specifika åtkomstkonfigurationer för enskilda slutpunkter använder du cmdleten Set-PSSessionConfiguration tillsammans med parametern AccessMode . För ytterligare information om sessionskonfigurationer, se about_Session_Configurations.

Kommentar

Även efter körning Disable-PSRemoting kan du fortfarande göra loopback-anslutningar på den lokala datorn. En loopback-anslutning är en PowerShell-fjärrsession som kommer från och ansluter till samma lokala dator. Fjärrsessioner från externa källor är fortfarande blockerade. För loopback-anslutningar måste du använda implicita autentiseringsuppgifter längs parametern EnableNetworkAccess . Mer information om loopback-anslutningar finns i New-PSSession.

Den här cmdleten är endast tillgänglig på Windows-plattformen. Den är inte tillgänglig i Linux- eller macOS-versioner av PowerShell. Om du vill köra den här cmdleten startar du PowerShell med alternativet Kör som administratör .

Exempel

Exempel 1: Förhindra fjärråtkomst till alla PowerShell-sessionskonfigurationer

Det här exemplet förhindrar fjärråtkomst till alla PowerShell-sessionsslutpunktskonfigurationer på datorn.

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.

Exempel 2: Förhindra fjärråtkomst till alla PowerShell-sessionskonfigurationer utan bekräftelse

Det här exemplet förhindrar fjärråtkomst till alla PowerShell-sessionsslutpunktskonfigurationer på datorn utan att fråga.

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.

Exempel 3: Effekter av att köra den här cmdleten

Det här exemplet visar effekten av att använda cmdleten Disable-PSRemoting . Om du vill köra den här kommandosekvensen startar du PowerShell med alternativet Kör som administratör .

När du har inaktiverat sessionskonfigurationerna försöker cmdleten New-PSSession skapa en fjärrsession till den lokala datorn (kallas även "loopback"). Eftersom fjärråtkomst är inaktiverat på den lokala datorn misslyckas kommandot.

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

Exempel 4: Effekter av att köra den här cmdleten och Enable-PSRemoting

Det här exemplet visar effekten på sessionskonfigurationerna för att använda Disable-PSRemoting cmdletarna och Enable-PSRemoting .

Disable-PSRemoting används för att inaktivera fjärråtkomst till alla PowerShell-sessionsslutpunktskonfigurationer. Force-parametern utelämnar alla användarprompter. Cmdletarna Get-PSSessionConfiguration och Format-Table visar sessionskonfigurationerna på datorn.

Utdata visar att alla fjärranvändare med en nätverkstoken nekas åtkomst till slutpunktskonfigurationerna. Gruppen Administratörer på den lokala datorn får åtkomst till slutpunktskonfigurationerna så länge de ansluter lokalt (kallas även loopback) och använder implicita autentiseringsuppgifter.

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 ...

Cmdleten Enable-PSRemoting återaktiver fjärråtkomst till alla PowerShell-sessionsslutpunktskonfigurationer på datorn. Force-parametern undertrycker alla användarprompter och startar om WinRM-tjänsten utan att fråga. De nya utdata visar att AccessDenied-säkerhetsbeskrivningarna har tagits bort från alla sessionskonfigurationer.

Exempel 5: Loopback-anslutningar med inaktiverade sessionsslutpunktskonfigurationer

Det här exemplet visar hur slutpunktskonfigurationer inaktiveras och visar hur du gör en lyckad loopback-anslutning till en inaktiverad slutpunkt. Disable-PSRemoting inaktiverar alla PowerShell-sessionsslutpunktskonfigurationer.

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

Den första användningen av New-PSSession försök att skapa en fjärrsession till den lokala datorn. Parametern ConfigurationName används för att ange en inaktiverad PowerShell-slutpunkt. Autentiseringsuppgifter skickas uttryckligen till kommandot via parametern Credential . Den här typen av anslutning går via nätverksstacken och är inte en loopback. Anslutningsförsöket till den inaktiverade slutpunkten misslyckas därför med ett åtkomstfel .

Den andra användningen av New-PSSession försöker också skapa en fjärrsession till den lokala datorn. I det här fallet lyckas det eftersom det är en loopback-anslutning som kringgår nätverksstacken.

En loopback-anslutning skapas när följande villkor uppfylls:

  • Datornamnet som ska anslutas till är "localhost".
  • Inga autentiseringsuppgifter skickas in. Aktuell inloggad användare (implicita autentiseringsuppgifter) används för anslutningen.
  • Switchparametern EnableNetworkAccess används.

Mer information om loopback-anslutningar finns i dokumentet New-PSSession .

Exempel 6: Inaktivera alla PowerShell-fjärrkommunikationsslutpunktskonfigurationer

Det här exemplet visar hur körning av Disable-PSRemoting kommandot inte påverkar Windows PowerShell-slutpunktskonfigurationer. Get-PSSessionConfiguration kör i Windows PowerShell visar alla slutpunktskonfigurationer. Vi ser att Windows PowerShell-slutpunktskonfigurationerna inte är inaktiverade.

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

Om du vill inaktivera dessa slutpunktskonfigurationer Disable-PSRemoting måste kommandot köras inifrån en Windows PowerShell-session. Get-PSSessionConfiguration Kör nu inifrån Windows PowerShell visar att alla slutpunktskonfigurationer är inaktiverade.

Exempel 7: Förhindra fjärråtkomst till sessionskonfigurationer som har anpassade säkerhetsbeskrivningar

Det här exemplet visar att cmdleten Disable-PSRemoting inaktiverar fjärråtkomst till alla sessionskonfigurationer som innehåller sessionskonfigurationer med anpassade säkerhetsbeskrivningar.

Register-PSSessionConfigurationskapar testsessionskonfigurationen. Parametern FilePath anger en sessionskonfigurationsfil som anpassar sessionen. Parametern ShowSecurityDescriptorUI visar en dialogruta som anger behörigheter för sessionskonfigurationen. I dialogrutan Behörigheter skapar vi anpassade behörigheter för fullständig åtkomst för den angivna användaren.

Cmdletarna Get-PSSessionConfiguration och Format-Table visar sessionskonfigurationerna och deras egenskaper. Utdata visar att testsessionskonfigurationen tillåter interaktiv åtkomst och särskilda behörigheter för den angivna användaren.

Disable-PSRemoting inaktiverar fjärråtkomst till alla sessionskonfigurationer.

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 Nu visar cmdletarna och Format-Table att en AccessDenied-säkerhetsbeskrivning för alla nätverksanvändare läggs till i alla sessionskonfigurationer, inklusive testsessionskonfigurationen. Även om de andra säkerhetsbeskrivningarna inte ändras har säkerhetsbeskrivningen "network_deny_all" företräde. Detta illustreras av försöket att ansluta New-PSSession till testsessionskonfigurationen.

Exempel 8: Återaktivera fjärråtkomst till valda sessionskonfigurationer

Det här exemplet visar hur du återaktiverar fjärråtkomst endast till valda sessionskonfigurationer. När du har inaktiverat alla sessionskonfigurationer aktiverar vi en specifik session igen.

Cmdleten Set-PSSessionConfiguration används för att ändra PowerShell.6-sessionskonfigurationen . Parametern AccessMode med värdet Fjärråteraktivering av fjärråtkomst till konfigurationen.

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 ...

Parametrar

-Confirm

Uppmanar dig att bekräfta innan du kör cmdleten.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

Tvingar kommandot att köras utan att be om användarbekräftelse.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Visar vad som skulle hända om cmdleten kördes. Cmdleten körs inte.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Indata

None

Du kan inte skicka objekt till den här cmdleten.

Utdata

None

Den här cmdleten returnerar inga utdata.

Kommentarer

Den här cmdleten är endast tillgänglig på Windows-plattformar.

  • Om du inaktiverar sessionskonfigurationerna ångras inte alla ändringar som gjorts av Enable-PSRemoting cmdletarna eller Enable-PSSessionConfiguration . Du kan behöva ångra följande ändringar manuellt.

    1. Stoppa och inaktivera WinRM-tjänsten.
    2. Ta bort lyssnaren som accepterar begäranden på alla IP-adresser.
    3. Inaktivera brandväggsfelen för WS-Management-kommunikation.
    4. Återställ värdet för LocalAccountTokenFilterPolicy till 0, vilket begränsar fjärråtkomsten till medlemmar i gruppen Administratörer på datorn.
  • En sessionsslutpunktskonfiguration är en grupp med inställningar som definierar miljön för en session. Varje session som ansluter till datorn måste använda någon av de sessionsslutpunktskonfigurationer som är registrerade på datorn. Genom att neka fjärråtkomst till alla konfigurationer av sessionsslutpunkter förhindrar du effektivt fjärranvändare från att upprätta sessioner som ansluter till datorn.