Disable-PSRemoting

Impedisce agli endpoint di PowerShell di ricevere connessioni remote.

Sintassi

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

Descrizione

Questo cmdlet è disponibile solo nella piattaforma Windows.

Il Disable-PSRemoting cmdlet blocca l'accesso remoto a tutte le configurazioni degli endpoint di sessione di PowerShell versione 6 e successive nel computer locale. Non influisce sulle configurazioni degli endpoint di Windows PowerShell. Per disabilitare le configurazioni degli endpoint di sessione di Windows PowerShell, eseguire Disable-PSRemoting il comando dall'interno di una sessione di Windows PowerShell.

Per riabilitare l'accesso remoto a tutte le configurazioni degli endpoint di sessione di PowerShell versione 6 e successive, usare il Enable-PSRemoting cmdlet . Per riabilitare l'accesso remoto a tutte le configurazioni dell'endpoint sessione di Windows PowerShell, eseguire Enable-PSRemoting da una sessione di Windows PowerShell.

Nota

Se si vuole disabilitare l'accesso remoto di PowerShell a un computer Windows locale, è necessario eseguire questo comando sia da una sessione all'interno di PowerShell versione 6 che successiva e dall'interno di una sessione di Windows PowerShell. Windows PowerShell viene installato in tutti i computer Windows per impostazione predefinita.

Per disabilitare e riabilitare l'accesso remoto a configurazioni specifiche dell'endpoint sessione, usare i Enable-PSSessionConfiguration cmdlet e Disable-PSSessionConfiguration . Per impostare configurazioni di accesso specifiche dei singoli endpoint, usare il Set-PSSessionConfiguration cmdlet insieme al parametro AccessMode . Per altre informazioni sulle configurazioni di sessione, vedere about_Session_Configurations.

Nota

Anche dopo l'esecuzione Disable-PSRemoting è comunque possibile effettuare connessioni di loopback nel computer locale. Una connessione loopback è una sessione remota di PowerShell che ha origine e si connette allo stesso computer locale. Le sessioni remote da origini esterne rimangono bloccate. Per le connessioni loopback è necessario usare credenziali implicite lungo il parametro EnableNetworkAccess . Per altre informazioni sulle connessioni loopback, vedere New-PSSession.

Questo cmdlet è disponibile solo nella piattaforma Windows. Non è disponibile nelle versioni linux o macOS di PowerShell. Per eseguire questo cmdlet, avviare PowerShell con l'opzione Esegui come amministratore .

Esempio

Esempio 1: Impedire l'accesso remoto a tutte le configurazioni di sessione di PowerShell

In questo esempio viene impedito l'accesso remoto a tutte le configurazioni degli endpoint di sessione di PowerShell nel computer.

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.

Esempio 2: Impedire l'accesso remoto a tutte le configurazioni di sessione di PowerShell senza richiesta di conferma

In questo esempio viene impedito l'accesso remoto a tutte le configurazioni degli endpoint di sessione di PowerShell nel computer senza chiedere conferma.

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.

Esempio 3: Effetti dell'esecuzione di questo cmdlet

In questo esempio viene illustrato l'effetto dell'uso del Disable-PSRemoting cmdlet . Per eseguire questa sequenza di comandi, avviare PowerShell con l'opzione Esegui come amministratore .

Dopo aver disabilitato le configurazioni delle sessioni, il New-PSSession cmdlet tenta di creare una sessione remota nel computer locale (noto anche come "loopback"). Poiché l'accesso remoto è disabilitato nel computer locale, il comando ha esito negativo.

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

Esempio 4: Effetti dell'esecuzione di questo cmdlet e Enable-PSRemoting

In questo esempio viene illustrato l'effetto sulle configurazioni di sessione di usando i Disable-PSRemoting cmdlet e Enable-PSRemoting .

Disable-PSRemoting viene usato per disabilitare l'accesso remoto a tutte le configurazioni degli endpoint di sessione di PowerShell. Il parametro Force elimina tutte le richieste dell'utente. I Get-PSSessionConfiguration cmdlet e Format-Table visualizzano le configurazioni di sessione nel computer.

L'output mostra che tutti gli utenti remoti con un token di rete vengono negati l'accesso alle configurazioni dell'endpoint. Amministrazione istrators gruppo nel computer locale sono autorizzati ad accedere alle configurazioni dell'endpoint purché si connetta localmente (noto anche come loopback) e usando credenziali implicite.

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

Il Enable-PSRemoting cmdlet abilita nuovamente l'accesso remoto a tutte le configurazioni degli endpoint di sessione di PowerShell nel computer. Il parametro Force elimina tutte le richieste dell'utente e riavvia il servizio WinRM senza richiedere conferma. Il nuovo output mostra che i descrittori di sicurezza AccessDenied sono stati rimossi da tutte le configurazioni di sessione.

Esempio 5: Connessioni loopback con configurazioni dell'endpoint sessione disabilitate

Questo esempio illustra come le configurazioni degli endpoint sono disabilitate e illustra come stabilire una connessione loopback corretta a un endpoint disabilitato. Disable-PSRemoting disabilita tutte le configurazioni degli endpoint di sessione di PowerShell.

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

Primo utilizzo di tentativi di New-PSSession creare una sessione remota nel computer locale. Il parametro ConfigurationName viene usato per specificare un endpoint di PowerShell disabilitato. Le credenziali vengono passate in modo esplicito al comando tramite il parametro Credential . Questo tipo di connessione passa attraverso lo stack di rete e non è un loopback. Di conseguenza, il tentativo di connessione all'endpoint disabilitato ha esito negativo e viene negato un errore di Accesso.

Il secondo utilizzo di tenta anche di New-PSSession creare una sessione remota nel computer locale. In questo caso, ha esito positivo perché si tratta di una connessione loopback che ignora lo stack di rete.

Una connessione loopback viene creata quando vengono soddisfatte le condizioni seguenti:

  • Il nome del computer a cui connettersi è "localhost".
  • Non vengono passate credenziali. L'utente connesso corrente (credenziali implicite) viene usato per la connessione.
  • Viene usato il parametro dell'opzione EnableNetworkAccess .

Per altre informazioni sulle connessioni loopback, vedere il documento New-PSSession .

Esempio 6: Disabilitazione di tutte le configurazioni degli endpoint remoti di PowerShell

Questo esempio illustra come l'esecuzione del Disable-PSRemoting comando non influisce sulle configurazioni degli endpoint di Windows PowerShell. Get-PSSessionConfiguration l'esecuzione in Windows PowerShell mostra tutte le configurazioni degli endpoint. Si noterà che le configurazioni degli endpoint di Windows PowerShell non sono disabilitate.

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

Per disabilitare queste configurazioni di endpoint, il Disable-PSRemoting comando deve essere eseguito dall'interno di una sessione di Windows PowerShell. A questo punto, Get-PSSessionConfiguration eseguire da Windows PowerShell indica che tutte le configurazioni degli endpoint sono disabilitate.

Esempio 7: Impedire l'accesso remoto alle configurazioni di sessione con descrittori di sicurezza personalizzati

In questo esempio viene illustrato che il cmdlet disabilita l'accesso Disable-PSRemoting remoto a tutte le configurazioni di sessione che includono configurazioni di sessione con descrittori di sicurezza personalizzati.

Register-PSSessionConfiguration crea la configurazione della sessione di test . Il parametro FilePath specifica un file di configurazione della sessione che personalizza la sessione. Il parametro ShowSecurityDescriptorUI visualizza una finestra di dialogo che imposta le autorizzazioni per la configurazione della sessione. Nella finestra di dialogo Autorizzazioni vengono create autorizzazioni di accesso completo personalizzate per l'utente indicato.

I Get-PSSessionConfiguration cmdlet e Format-Table visualizzano le configurazioni di sessione e le relative proprietà. L'output mostra che la configurazione della sessione di test consente l'accesso interattivo e le autorizzazioni speciali per l'utente indicato.

Disable-PSRemoting disabilita l'accesso remoto a tutte le configurazioni di sessione.

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 I cmdlet e Format-Table mostrano ora che un descrittore di sicurezza AccessDenied per tutti gli utenti di rete viene aggiunto a tutte le configurazioni di sessione, inclusa la configurazione della sessione di test. Anche se gli altri descrittori di sicurezza non vengono modificati, il descrittore di sicurezza "network_deny_all" ha la precedenza. Questo è illustrato dal tentativo di usare New-PSSession per connettersi alla configurazione della sessione di test .

Esempio 8: Riabilitare l'accesso remoto alle configurazioni di sessione selezionate

Questo esempio illustra come riabilitare l'accesso remoto solo a determinate configurazioni di sessione. Dopo aver disabilitato tutte le configurazioni di sessione, si riabilita una sessione specifica.

Il Set-PSSessionConfiguration cmdlet viene usato per modificare la configurazione della sessione di PowerShell.6 . Il parametro AccessMode con il valore Remote re-abilita l'accesso remoto alla configurazione.

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

Parametri

-Confirm

Richiede conferma prima di eseguire il cmdlet.

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

-Force

Forza l'esecuzione del comando senza chiedere conferma all'utente.

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

-WhatIf

Mostra gli effetti dell'esecuzione del cmdlet. Il cmdlet non viene eseguito.

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

Input

None

Non è possibile inviare tramite pipe oggetti a questo cmdlet.

Output

None

Questo cmdlet non restituisce output.

Note

Questo cmdlet è disponibile solo nelle piattaforme Windows.

  • La disabilitazione delle configurazioni di sessione non annulla tutte le modifiche apportate dai Enable-PSRemoting cmdlet o Enable-PSSessionConfiguration . Può essere necessario annullare manualmente le modifiche seguenti.

    1. Arrestare e disabilitare il servizio WinRM.
    2. Eliminare il listener che accetta richieste in qualsiasi indirizzo IP.
    3. Disabilitare le eccezioni del firewall per le comunicazioni di WS-Management.
    4. Ripristinare il valore di LocalAccountTokenFilterPolicy su 0, che limita l'accesso remoto ai membri del gruppo Administrators nel computer.
  • Una configurazione dell'endpoint di sessione è un gruppo di impostazioni che definiscono l'ambiente per una sessione. Ogni sessione che si connette al computer deve usare una delle configurazioni dell'endpoint sessione registrate nel computer. Negando l'accesso remoto a tutte le configurazioni degli endpoint di sessione, si impedisce agli utenti remoti di stabilire sessioni che si connettono al computer.