Disable-PSRemoting
Impede que os pontos finais do PowerShell recebam ligações remotas.
Syntax
Disable-PSRemoting
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
Este cmdlet só está disponível na plataforma do Windows.
O Disable-PSRemoting
cmdlet bloqueia o acesso remoto a todas as configurações de ponto final de sessão do PowerShell versão 6 e superiores no computador local. Não afeta Windows PowerShell configurações de pontos finais. Para desativar Windows PowerShell configurações do ponto final de sessão, execute Disable-PSRemoting
o comando a partir de uma sessão Windows PowerShell.
Para reativar o acesso remoto a todas as configurações de ponto final de sessão do PowerShell versão 6 e superior, utilize o Enable-PSRemoting
cmdlet. Para reativar o acesso remoto a todas as configurações de ponto final de sessão Windows PowerShell, execute Enable-PSRemoting
a partir de uma sessão de Windows PowerShell.
Nota
Se quiser desativar todo o acesso remoto do PowerShell a um computador Windows local, tem de executar este comando a partir de uma sessão no PowerShell versão 6 ou superior e a partir de uma sessão Windows PowerShell. Windows PowerShell está instalado em todos os computadores Windows por predefinição.
Para desativar e reativar o acesso remoto a configurações específicas do ponto final de sessão, utilize os Enable-PSSessionConfiguration
cmdlets e Disable-PSSessionConfiguration
. Para definir configurações de acesso específicas de pontos finais individuais, utilize o Set-PSSessionConfiguration
cmdlet juntamente com o parâmetro AccessMode . Para obter mais informações sobre configurações de sessão, consulte about_Session_Configurations.
Nota
Mesmo depois de executar Disable-PSRemoting
, ainda pode efetuar ligações de loopback no computador local. Uma ligação de loopback é uma sessão remota do PowerShell que tem origem e se liga ao mesmo computador local. As sessões remotas de origens externas permanecem bloqueadas. Para ligações de loopback, tem de utilizar credenciais implícitas ao longo do parâmetro EnableNetworkAccess . Para obter mais informações sobre ligações de loopback, consulte New-PSSession.
Este cmdlet só está disponível na plataforma do Windows. Não está disponível em versões linux ou macOS do PowerShell. Para executar este cmdlet, inicie o PowerShell com a opção Executar como administrador .
Exemplos
Exemplo 1: Impedir o acesso remoto a todas as configurações de sessão do PowerShell
Este exemplo impede o acesso remoto a todas as configurações de ponto final de sessão do PowerShell no computador.
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.
Exemplo 2: Impedir o acesso remoto a todas as configurações de sessão do PowerShell sem aviso de confirmação
Este exemplo impede o acesso remoto a todas as configurações de ponto final de sessão do PowerShell no computador sem pedir.
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.
Exemplo 3: Efeitos da execução deste cmdlet
Este exemplo mostra o efeito da utilização do Disable-PSRemoting
cmdlet. Para executar esta sequência de comandos, inicie o PowerShell com a opção Executar como administrador .
Depois de desativar as configurações das sessões, o New-PSSession
cmdlet tenta criar uma sessão remota para o computador local (também conhecido como "loopback"). Uma vez que o acesso remoto está desativado no computador local, o comando falha.
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
Exemplo 4: Efeitos da execução deste cmdlet e Enable-PSRemoting
Este exemplo mostra o efeito nas configurações de sessão da utilização dos Disable-PSRemoting
cmdlets e Enable-PSRemoting
.
Disable-PSRemoting
é utilizado para desativar o acesso remoto a todas as configurações de ponto final de sessão do PowerShell. O parâmetro Force suprime todos os pedidos de utilizador. Os Get-PSSessionConfiguration
cmdlets e Format-Table
apresentam as configurações de sessão no computador.
A saída mostra que todos os utilizadores remotos com um token de rede têm acesso negado às configurações do ponto final. O grupo de administradores no computador local tem permissão para aceder às configurações do ponto final, desde que estejam a ligar-se localmente (também conhecido como loopback) e a utilizar credenciais implícitas.
Disable-PSRemoting -force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Auto
Enable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Auto
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 ...
O Enable-PSRemoting
cmdlet reativa o acesso remoto a todas as configurações de ponto final de sessão do PowerShell no computador. O parâmetro Force suprime todos os pedidos de utilizador e reinicia o serviço WinRM sem pedir. A nova saída mostra que os descritores de segurança do AccessDenied foram removidos de todas as configurações de sessão.
Exemplo 5: Ligações loopback com configurações de ponto final de sessão desativadas
Este exemplo demonstra como as configurações de ponto final estão desativadas e mostra como fazer uma ligação de loopback com êxito a um ponto final desativado. Disable-PSRemoting
desativa todas as configurações de ponto final de sessão do 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
A primeira utilização de New-PSSession
tentativas para criar uma sessão remota no computador local. O parâmetro ConfigurationName é utilizado para especificar um ponto final do PowerShell desativado. As credenciais são transmitidas explicitamente ao comando através do parâmetro Credencial . Este tipo de ligação passa pela pilha de rede e não é um loopback. Consequentemente, a tentativa de ligação ao ponto final desativado falha com um erro de Acesso negado .
A segunda utilização também New-PSSession
tenta criar uma sessão remota no computador local.
Neste caso, é bem-sucedido porque é uma ligação de loopback que ignora a pilha de rede.
É criada uma ligação de loopback quando são cumpridas as seguintes condições:
- O nome do computador a que ligar é "localhost".
- Não são transmitidas credenciais. O utilizador com sessão iniciada atual (credenciais implícitas) é utilizado para a ligação.
- É utilizado o parâmetro enableNetworkAccess switch.
Para obter mais informações sobre ligações de loopback, veja New-PSSession document (Documento New-PSSession ).
Exemplo 6: Desativar todas as configurações de ponto final de remo do PowerShell
Este exemplo demonstra como a execução do Disable-PSRemoting
comando não afeta Windows PowerShell configurações de pontos finais. Get-PSSessionConfiguration
a execução no Windows PowerShell mostra todas as configurações de pontos finais. Vemos que as configurações do ponto final Windows PowerShell não estão desativadas.
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
Para desativar estas configurações de ponto final, o Disable-PSRemoting
comando tem de ser executado a partir de uma sessão Windows PowerShell. Agora, Get-PSSessionConfiguration
executar a partir de Windows PowerShell mostra que todas as configurações de ponto final estão desativadas.
Exemplo 7: Impedir o acesso remoto a configurações de sessão que tenham descritores de segurança personalizados
Este exemplo demonstra que o cmdlet desativa o Disable-PSRemoting
acesso remoto a todas as configurações de sessão que incluem configurações de sessão com descritores de segurança personalizados.
Register-PSSessionConfiguration
cria a configuração da sessão de teste . O parâmetro FilePath especifica um ficheiro de configuração de sessão que personaliza a sessão. O parâmetro ShowSecurityDescriptorUI apresenta uma caixa de diálogo que define as permissões para a configuração da sessão. Na caixa de diálogo Permissões, criamos permissões de acesso total personalizadas para o utilizador indicado.
Os Get-PSSessionConfiguration
cmdlets e Format-Table
apresentam as configurações da sessão e as respetivas propriedades. A saída mostra que a configuração da sessão de teste permite o acesso interativo e permissões especiais para o utilizador indicado.
Disable-PSRemoting
desativa o acesso remoto a todas as configurações de sessão.
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
Agora, os Get-PSSessionConfiguration
cmdlets e Format-Table
mostram que um descritor de segurança do AccessDenied para todos os utilizadores de rede é adicionado a todas as configurações de sessão, incluindo a configuração da sessão de teste . Embora os outros descritores de segurança não sejam alterados, o descritor de segurança "network_deny_all" tem precedência. Isto é ilustrado pela tentativa de utilizar New-PSSession
para ligar à configuração da sessão de teste .
Exemplo 8: Reativar o acesso remoto às configurações de sessão selecionadas
Este exemplo mostra como reativar o acesso remoto apenas às configurações de sessão selecionadas. Depois de desativar todas as configurações de sessão, reativamos uma sessão específica.
O Set-PSSessionConfiguration
cmdlet é utilizado para alterar a configuração da sessão do PowerShell.6 . O parâmetro AccessMode com um valor de Remoto reativa o acesso remoto à configuração.
Disable-PSRemoting -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Auto
Set-PSSessionConfiguration -Name PowerShell.6 -AccessMode Remote -Force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Auto
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 ...
Parâmetros
-Confirm
Solicita a sua confirmação antes de executar o cmdlet.
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Force
Força o comando a ser executado sem pedir a confirmação do utilizador.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
Apresenta o que aconteceria mediante a execução do cmdlet. O cmdlet não é executado.
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Entradas
None
Não pode encaminhar objetos para este cmdlet.
Saídas
None
Este cmdlet não devolve nenhuma saída.
Notas
Este cmdlet só está disponível em plataformas do Windows.
Desativar as configurações de sessão não anula todas as alterações efetuadas pelos
Enable-PSRemoting
cmdlets ouEnable-PSSessionConfiguration
. Poderá ter de anular manualmente as seguintes alterações.- Pare e desative o serviço WinRM.
- Elimine o serviço de escuta que aceita pedidos em qualquer endereço IP.
- Desative as exceções de firewall para comunicações WS-Management.
- Restaure o valor de LocalAccountTokenFilterPolicy para 0, o que restringe o acesso remoto aos membros do grupo Administradores no computador.
Uma configuração de ponto final de sessão é um grupo de definições que definem o ambiente para uma sessão. Todas as sessões que se ligam ao computador têm de utilizar uma das configurações de ponto final de sessão registadas no computador. Ao negar o acesso remoto a todas as configurações de ponto final de sessão, impede efetivamente que os utilizadores remotos estabeleçam sessões que se liguem ao computador.
Ligações Relacionadas
Comentários
Submeter e ver comentários