Delen via


Disable-PSRemoting

Hiermee voorkomt u dat PowerShell-eindpunten externe verbindingen ontvangen.

Syntaxis

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

Description

De Disable-PSRemoting cmdlet blokkeert externe toegang tot alle configuraties van windows PowerShell-sessie-eindpunten op de lokale computer. Dit omvat alle eindpunten die zijn gemaakt door PowerShell 6 of hoger.

Als u externe toegang tot alle sessieconfiguraties opnieuw wilt inschakelen, gebruikt u de cmdlet Enable-PSRemoting. Dit omvat alle eindpunten die zijn gemaakt door PowerShell 6 of hoger. Als u externe toegang tot geselecteerde sessieconfiguraties wilt inschakelen, gebruikt u de parameter AccessMode van de Set-PSSessionConfiguration-cmdlet. U kunt ook de cmdlets Enable-PSSessionConfiguration en Disable-PSSessionConfiguration gebruiken om sessieconfiguraties voor alle gebruikers in en uit te schakelen. Zie about_Session_Configurationsvoor meer informatie over sessieconfiguraties.

Notitie

Zelfs nadat u Disable-PSRemoting hebt uitgevoerd, kunt u nog steeds loopback-verbindingen maken op de lokale computer. Een loopback-verbinding is een externe PowerShell-sessie die afkomstig is van en verbinding maakt met dezelfde lokale computer. Externe sessies van externe bronnen blijven geblokkeerd. Voor loopback-verbindingen moet u impliciete referenties gebruiken in de parameter EnableNetworkAccess. Zie New-PSSessionvoor meer informatie over loopback-verbindingen.

Als u deze cmdlet wilt uitvoeren, start u Windows PowerShell met de optie Als administrator uitvoeren.

Voorbeelden

Voorbeeld 1: Externe toegang tot alle sessieconfiguraties voorkomen

In dit voorbeeld voorkomt u externe toegang tot alle configuraties van powerShell-sessie-eindpunten op de computer.

Disable-PSRemoting

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.

Voorbeeld 2: Externe toegang tot alle sessieconfiguraties voorkomen zonder bevestigingsprompt

In dit voorbeeld voorkomt u dat alle configuraties van powerShell-sessie-eindpunten op de computer worden geconfigureerd zonder dat u hierom wordt gevraagd.

Disable-PSRemoting -Force

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.

Voorbeeld 3: Effecten van het uitvoeren van deze cmdlet

In dit voorbeeld ziet u het effect van het gebruik van de cmdlet Disable-PSRemoting. Als u deze opdrachtreeks wilt uitvoeren, start u PowerShell met de optie Als administrator uitvoeren.

Nadat de sessieconfiguraties zijn uitgeschakeld, probeert de New-PSSession cmdlet een externe sessie naar de lokale computer te maken (ook wel een 'loopback' genoemd). Omdat externe toegang is uitgeschakeld op de lokale computer, mislukt de opdracht.

Disable-PSRemoting -Force
New-PSSession -ComputerName localhost

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

Voorbeeld 4: Effecten van het uitvoeren van deze cmdlet en Enable-PSRemoting

In dit voorbeeld ziet u het effect op de sessieconfiguraties van het gebruik van de cmdlets Disable-PSRemoting en Enable-PSRemoting.

Disable-PSRemoting wordt gebruikt om externe toegang tot alle configuraties van powerShell-sessie-eindpunten uit te schakelen. De parameter Forceren onderdrukt alle gebruikersprompts. De cmdlets Get-PSSessionConfiguration en Format-Table geven de sessieconfiguraties op de computer weer.

In de uitvoer ziet u dat alle externe gebruikers met een netwerktoken geen toegang hebben tot de eindpuntconfiguraties. Beheerdersgroep op de lokale computer heeft toegang tot de eindpuntconfiguraties zolang ze lokaal verbinding maken (ook wel loopback genoemd) en impliciete referenties gebruiken.

Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize

Enable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize

Name                          Permission
----                          ----------
microsoft.powershell          NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell.workflow NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell32        NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.ServerManager       NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
WithProfile                   NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed

Name                          Permission
----                          ----------
microsoft.powershell          BUILTIN\Administrators AccessAllowed
microsoft.powershell.workflow BUILTIN\Administrators AccessAllowed
microsoft.powershell32        BUILTIN\Administrators AccessAllowed
microsoft.ServerManager       BUILTIN\Administrators AccessAllowed
WithProfile                   BUILTIN\Administrators AccessAllowed

De Enable-PSRemoting cmdlet schakelt externe toegang opnieuw in voor alle configuraties van powerShell-sessie-eindpunten op de computer. De parameter Forceren onderdrukt alle gebruikersprompts en start de WinRM-service opnieuw zonder te vragen. In de nieuwe uitvoer ziet u dat de AccessDenied security descriptors zijn verwijderd uit alle sessieconfiguraties.

Voorbeeld 5: Loopback-verbindingen met uitgeschakelde configuraties van sessie-eindpunten

In dit voorbeeld ziet u hoe eindpuntconfiguraties zijn uitgeschakeld en ziet u hoe u een geslaagde loopback-verbinding maakt met een uitgeschakeld eindpunt. Disable-PSRemoting schakelt alle configuraties van powerShell-sessie-eindpunten uit.

Disable-PSRemoting -Force
New-PSSession -ComputerName localhost

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
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
   gTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed

New-PSSession -ComputerName localhost -EnableNetworkAccess

Id Name       Transport ComputerName  ComputerType   State   ConfigurationName   Availability
 -- ----       --------- ------------  ------------   -----   -----------------   ------------
 1  Runspace1  WSMan     localhost     RemoteMachine  Opened  powershell.6           Available

Het eerste gebruik van New-PSSession probeert een externe sessie te maken op de lokale computer. Dit type verbinding gaat via de netwerkstack en is geen loopback. Als gevolg hiervan mislukt de verbindingspoging naar het uitgeschakelde eindpunt met een Access wordt geweigerd fout.

Het tweede gebruik van New-PSSession probeert ook een externe sessie naar de lokale computer te maken. In dit geval lukt het omdat het een loopback-verbinding is die de netwerkstack omzeilt.

Er wordt een loopback-verbinding gemaakt wanneer aan de volgende voorwaarden wordt voldaan:

  • De computernaam waarmee verbinding moet worden gemaakt, is 'localhost'.
  • Er worden geen referenties doorgegeven. De huidige aangemelde gebruiker (impliciete referenties) wordt gebruikt voor de verbinding.
  • De parameter EnableNetworkAccess switch wordt gebruikt.

Zie document new-PSSession voor meer informatie over loopbackverbindingen.

Voorbeeld 6: Externe toegang tot sessieconfiguraties met aangepaste beveiligingsdescriptors voorkomen

In dit voorbeeld ziet u dat de Disable-PSRemoting cmdlet externe toegang uitschakelt tot alle sessieconfiguraties met sessieconfiguraties met aangepaste beveiligingsdescriptors.

Register-PSSessionConfiguration maakt de configuratie van de test sessie. De parameter FilePath geeft een sessieconfiguratiebestand op waarmee de sessie wordt aangepast. De parameter ShowSecurityDescriptorUI geeft een dialoogvenster weer waarin machtigingen voor de sessieconfiguratie worden ingesteld. In het dialoogvenster Machtigingen maken we aangepaste machtigingen voor volledige toegang voor de aangegeven gebruiker.

De cmdlets Get-PSSessionConfiguration en Format-Table geven de sessieconfiguraties en de bijbehorende eigenschappen weer. In de uitvoer ziet u dat de configuratie van de Test sessie interactieve toegang en speciale machtigingen voor de opgegeven gebruiker toestaat.

Disable-PSRemoting schakelt externe toegang tot alle sessieconfiguraties uit.

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
----                          ----------
microsoft.powershell          BUILTIN\Administrators AccessAllowed
Test                          NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed,
DOMAIN01\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
----                          ----------
microsoft.powershell          NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
Test                          NT AUTHORITY\NETWORK AccessDenied, NTAUTHORITY\INTERACTIVE AccessAllowed,
BUILTIN\Administrators AccessAllowed, DOMAIN01\User01 AccessAllowed


[Server01] Connecting to remote server failed with the following error message : Access is denied. For more information, see the about_Rem
ote_Troubleshooting Help topic.
+ CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed

De cmdlets Get-PSSessionConfiguration en Format-Table laten nu zien dat een AccessDenied security descriptor voor alle netwerkgebruikers wordt toegevoegd aan alle sessieconfiguraties, inclusief de test sessieconfiguratie. Hoewel de andere beveiligingsdescriptors niet worden gewijzigd, heeft de beveiligingsdescriptor 'network_deny_all' voorrang. Dit wordt geïllustreerd door de poging om New-PSSession te gebruiken om verbinding te maken met de Test sessieconfiguratie.

Voorbeeld 7: Externe toegang opnieuw inschakelen voor geselecteerde sessieconfiguraties

In dit voorbeeld ziet u hoe u externe toegang alleen opnieuw inschakelt voor geselecteerde sessieconfiguraties. Nadat alle sessieconfiguraties zijn uitgeschakeld, schakelen we een specifieke sessie opnieuw in.

De Set-PSSessionConfiguration cmdlet wordt gebruikt om de microsoft te wijzigen. ServerManager sessieconfiguratie. De parameter AccessMode met de waarde Remote externe toegang tot de configuratie opnieuw inschakelt.

Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -AutoSize

Set-PSSessionConfiguration -Name Microsoft.ServerManager -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
----                          ----------
microsoft.powershell          NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell.workflow NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell32        NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.ServerManager       NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
WithProfile                   NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed

Name                          Permission
----                          ----------
microsoft.powershell          NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell.workflow NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.powershell32        NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed
microsoft.ServerManager       BUILTIN\Administrators AccessAllowed
WithProfile                   NT AUTHORITY\NETWORK AccessDenied, BUILTIN\Administrators AccessAllowed

Parameters

-Confirm

U wordt gevraagd om bevestiging voordat u de cmdlet uitvoert.

Type:SwitchParameter
Aliassen:cf
Position:Named
Default value:False
Vereist:False
Pijplijninvoer accepteren:False
Jokertekens accepteren:False

-Force

Hiermee dwingt u de opdracht uit te voeren zonder dat u om bevestiging van de gebruiker wordt gevraagd.

Type:SwitchParameter
Position:Named
Default value:None
Vereist:False
Pijplijninvoer accepteren:False
Jokertekens accepteren:False

-WhatIf

Toont wat er zou gebeuren als de cmdlet wordt uitgevoerd. De cmdlet wordt niet uitgevoerd.

Type:SwitchParameter
Aliassen:wi
Position:Named
Default value:False
Vereist:False
Pijplijninvoer accepteren:False
Jokertekens accepteren:False

Invoerwaarden

None

U kunt geen objecten doorsluisen naar deze cmdlet.

Uitvoerwaarden

None

Deze cmdlet retourneert geen uitvoer.

Notities

  • Als u de sessieconfiguraties uitschakelt, worden niet alle wijzigingen ongedaan gemaakt die zijn aangebracht door de Enable-PSRemoting of Enable-PSSessionConfiguration cmdlets. Mogelijk moet u de volgende wijzigingen handmatig ongedaan maken.

    1. Stop en schakel de WinRM-service uit.
    2. Verwijder de listener die aanvragen accepteert op elk IP-adres.
    3. Schakel de firewall-uitzonderingen voor WS-Management communicatie uit.
    4. Herstel de waarde van localAccountTokenFilterPolicy naar 0, waardoor externe toegang wordt beperkt tot leden van de groep Administrators op de computer.

    Een sessieconfiguratie is een groep instellingen waarmee de omgeving voor een sessie wordt gedefinieerd. Elke sessie die verbinding maakt met de computer, moet een van de sessieconfiguraties gebruiken die zijn geregistreerd op de computer. Door externe toegang tot alle sessieconfiguraties te weigeren, voorkomt u effectief dat externe gebruikers sessies tot stand brengen die verbinding maken met de computer.

    In Windows PowerShell 2.0 voegt Disable-PSRemoting een Deny_All vermelding toe aan de beveiligingsdescriptors van alle sessieconfiguraties. Met deze instelling voorkomt u dat alle gebruikers door gebruikers beheerde sessies maken op de lokale computer. In Windows PowerShell 3.0 voegt Disable-PSRemoting een Network_Deny_All vermelding toe aan de beveiligingsdescriptors van alle sessieconfiguraties. Met deze instelling voorkomt u dat gebruikers op andere computers door gebruikers beheerde sessies maken op de lokale computer, maar gebruikers van de lokale computer toestaan om door gebruikers beheerde loopbacksessies te maken.

    In Windows PowerShell 2.0 is Disable-PSRemoting het equivalent van Disable-PSSessionConfiguration -Name *. In windows PowerShell 3.0 en hoger is Disable-PSRemoting het equivalent van Set-PSSessionConfiguration -Name \<Configuration name\> -AccessMode Local