Disable-PSRemoting

PowerShell エンドポイントがリモート接続を受信できないようにします。

構文

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

説明

コマンドレットはDisable-PSRemoting、ローカル コンピューター上のすべてのWindows PowerShellセッション エンドポイント構成へのリモート アクセスをブロックします。 これには、PowerShell 6 以降によって作成されたすべてのエンドポイントが含まれます。

すべてのセッション構成へのリモート アクセスを再度有効にするには、 コマンドレットを使用します Enable-PSRemoting 。 これには、PowerShell 6 以降によって作成されたすべてのエンドポイントが含まれます。 選択したセッション構成へのリモート アクセスを有効にするには、 コマンドレットの AccessMode パラメーターを Set-PSSessionConfiguration 使用します。 および Disable-PSSessionConfiguration コマンドレットをEnable-PSSessionConfiguration使用して、すべてのユーザーのセッション構成を有効または無効にすることもできます。 セッション構成の詳細については、「 about_Session_Configurations」を参照してください。

Note

を実行 Disable-PSRemoting した後でも、ローカル コンピューターでループバック接続を行うことができます。 ループバック接続は、同じローカル コンピューターから発信され、同じローカル コンピューターに接続される PowerShell リモート セッションです。 外部ソースからのリモート セッションはブロックされたままです。 ループバック接続の場合は、 EnableNetworkAccess パラメーターに沿って暗黙的な資格情報を使用する必要があります。 ループバック接続の詳細については、「 New-PSSession」を参照してください。

このコマンドレットを実行するには、[管理者として実行] オプションを使用してWindows PowerShellを開始します。

例 1: すべてのセッション構成へのリモート アクセスを禁止する

この例では、コンピューター上のすべての PowerShell セッション エンドポイント構成へのリモート アクセスを禁止します。

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.

例 2: 確認プロンプトなしですべてのセッション構成へのリモート アクセスを禁止する

この例では、プロンプトを表示せずに、コンピューター上のすべての PowerShell セッション エンドポイント構成にリモート アクセスできないようにします。

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.

例 3: このコマンドレットを実行した場合の影響

この例では、 コマンドレットを使用した場合の効果を Disable-PSRemoting 示します。 このコマンド シーケンスを実行するには、[ 管理者として実行 ] オプションを使用して PowerShell を起動します。

セッション構成を無効にすると、コマンドレットは New-PSSession ローカル コンピューター ("ループバック" とも呼ばれます) へのリモート セッションの作成を試みます。 ローカル コンピューターではリモート アクセスが無効になっているため、コマンドは失敗します。

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

例 4: このコマンドレットとEnable-PSRemotingを実行した場合の影響

この例では、 コマンドレットと Enable-PSRemoting コマンドレットを使用したセッション構成への影響をDisable-PSRemoting示します。

Disable-PSRemoting は、すべての PowerShell セッション エンドポイント構成へのリモート アクセスを無効にするために使用されます。 Force パラメーターにより、すべてのユーザー メッセージが表示されなくなります。 Get-PSSessionConfigurationコマンドレットと Format-Table コマンドレットは、コンピューター上のセッション構成を表示します。

出力は、ネットワーク トークンを持つすべてのリモート ユーザーがエンドポイント構成へのアクセスを拒否されたことを示しています。 ローカル コンピューター上の Administrators グループは、ローカルに接続し (ループバックとも呼ばれます)、暗黙的な資格情報を使用している限り、エンドポイント構成へのアクセスを許可されます。

Disable-PSRemoting -force
Get-PSSessionConfiguration | Format-Table -Property Name, Permission -Auto

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

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

コマンドレットを Enable-PSRemoting 使用すると、コンピューター上のすべての PowerShell セッション エンドポイント構成へのリモート アクセスが再度有効になります。 Force パラメーターは、すべてのユーザー プロンプトを抑制し、プロンプトを表示せずに WinRM サービスを再起動します。 新しい出力は、 AccessDenied セキュリティ記述子がすべてのセッション構成から削除されたことを示しています。

例 5: セッション エンドポイント構成が無効になっているループバック接続

この例では、エンドポイント構成を無効にする方法を示し、無効なエンドポイントへのループバック接続を成功させる方法を示します。 Disable-PSRemoting は、すべての PowerShell セッション エンドポイント構成を無効にします。

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

ローカル コンピューターへのリモート セッションの作成の最初の使用 New-PSSession 。 この種類の接続はネットワーク スタックを経由し、ループバックではありません。 その結果、無効なエンドポイントへの接続試行 は、Access が拒否された エラーで失敗します。

の 2 番目の New-PSSession 使用では、ローカル コンピューターへのリモート セッションの作成も試行されます。 この場合、ネットワーク スタックをバイパスするループバック接続であるため、成功します。

次の条件が満たされると、ループバック接続が作成されます。

  • 接続するコンピューター名は 'localhost' です。
  • 資格情報は渡されません。 現在ログインしているユーザー (暗黙的な資格情報) が接続に使用されます。
  • EnableNetworkAccess スイッチ パラメーターが使用されます。

ループバック接続の詳細については、「 New-PSSession ドキュメント」を参照してください。

例 6: カスタム セキュリティ記述子を持つセッション構成へのリモート アクセスを禁止する

この例では、コマンドレットによって Disable-PSRemoting 、カスタム セキュリティ記述子を使用したセッション構成を含むすべてのセッション構成へのリモート アクセスが無効になっていることを示します。

Register-PSSessionConfigurationは、テスト セッション構成を作成します。 FilePath パラメーターは、セッションをカスタマイズするセッション構成ファイルを指定します。 ShowSecurityDescriptorUI パラメーターには、セッション構成のアクセス許可を設定するダイアログ ボックスが表示されます。 [アクセス許可] ダイアログ ボックスで、指定されたユーザーのカスタム フル アクセス許可を作成します。

Get-PSSessionConfigurationコマンドレットと Format-Table コマンドレットには、セッション構成とそのプロパティが表示されます。 出力は、 テスト セッション構成で、指定されたユーザーに対する対話型アクセスと特別なアクセス許可を許可することを示しています。

Disable-PSRemoting は、すべてのセッション構成へのリモート アクセスを無効にします。

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

これで、 Get-PSSessionConfiguration コマンドレットと Format-Table コマンドレットは、すべてのネットワーク ユーザーの AccessDenied セキュリティ記述子が、 テスト セッション構成を含むすべてのセッション構成に追加されることを示しています。 他のセキュリティ記述子は変更されませんが、"network_deny_all" セキュリティ記述子が優先されます。 これは、テスト セッション構成への接続に を使用New-PSSessionしようとした場合に示されています。

例 7: 選択したセッション構成へのリモート アクセスを再度有効にする

この例では、選択したセッション構成にのみリモート アクセスを再度有効にする方法を示します。 すべてのセッション構成を無効にした後、特定のセッションを再度有効にします。

コマンドレットは Set-PSSessionConfiguration 、microsoft を変更するために使用 されます。ServerManager セッション構成。 値が RemoteAccessMode パラメーターは、構成へのリモート アクセスを再び有効にします。

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

Set-PSSessionConfiguration -Name Microsoft.ServerManager -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
----                          ----------
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

パラメーター

-Confirm

コマンドレットの実行前に確認を求めるメッセージが表示されます。

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

-Force

ユーザーに確認せずに、直ちにコマンドを実行します。

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

-WhatIf

コマンドレットの実行時に発生する内容を示します。 このコマンドレットは実行されません。

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

入力

None

オブジェクトをこのコマンドレットにパイプすることはできません。

出力

None

このコマンドレットは、出力を返しません。

メモ

  • セッション構成を無効にしても、 または Enable-PSSessionConfiguration コマンドレットによって行われたすべての変更が元にEnable-PSRemoting戻されるわけではありません。 場合によっては次の変更を手動で元に戻す必要があります。

    1. WinRM サービスを停止して無効にする。
    2. 任意の IP アドレスで要求を受け入れるリスナーを削除する。
    3. WS-Management 通信用のファイアウォールの例外を無効にする。
    4. LocalAccountTokenFilterPolicy の値を 0 に復元して、リモート アクセスをコンピューターの Administrators グループのメンバーに制限する。

    セッション構成は、セッションの環境を定義する設定のグループです。 コンピューターに接続するすべてのセッションは、コンピューターに登録されているセッション構成のいずれかを使用する必要があります。 すべてのセッション構成へのリモート アクセスを拒否することにより、リモート ユーザーがコンピューターに接続するセッションを確立するのを効果的に防止できます。

    Windows PowerShell 2.0 では、Disable-PSRemotingすべてのセッション構成のセキュリティ記述子にDeny_Allエントリを追加します。 この設定により、すべてのユーザーがローカル コンピューターへのユーザー管理セッションを作成できなくなります。 Windows PowerShell 3.0 では、Disable-PSRemotingすべてのセッション構成のセキュリティ記述子にNetwork_Deny_Allエントリを追加します。 この設定により、他のコンピューターのユーザーがローカル コンピューターでユーザー管理セッションを作成できなくなりますが、ローカル コンピューターのユーザーはユーザーが管理するループバック セッションを作成できます。

    Windows PowerShell 2.0 では、 Disable-PSRemoting は と同等ですDisable-PSSessionConfiguration -Name *。 Windows PowerShell 3.0 以降のリリースでは、 Disable-PSRemoting は と同等です。Set-PSSessionConfiguration -Name \<Configuration name\> -AccessMode Local