Disable-PSRemoting

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

構文

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

説明

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

すべてのセッション構成へのリモート アクセスを再度有効にするには、コマンドレットを Enable-PSRemoting 使用します。 これには、PowerShell 6 以降で作成されたすべてのエンドポイントが含まれます。 選択したセッション構成へのリモート アクセスを有効にするには、コマンドレットの AccessMode パラメーターを Set-PSSessionConfiguration 使用します。 また、コマンドレットをEnable-PSSessionConfigurationDisable-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 を実行した場合の影響

この例では、and コマンドレットを使用するセッション構成に対する影響をDisable-PSRemotingEnable-PSRemoting示します。

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

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

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

このコマンドレットは 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 パラメーターには、セッション構成のアクセス許可を設定するダイアログ ボックスが表示されます。 [アクセス許可] ダイアログ ボックスでは、指定されたユーザーに対してカスタムのフル アクセス許可を作成します。

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

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

パラメーター

-Confirm

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

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

-Force

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

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

-WhatIf

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

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required: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-PSRemotingDisable-PSSessionConfiguration -Name * Windows PowerShell 3.0 以降のリリースでは、 Disable-PSRemotingSet-PSSessionConfiguration -Name \<Configuration name\> -AccessMode Local