Disable-PSRemoting

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

構文

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

説明

このコマンドレットは、Windows プラットフォームでのみ使用できます。

このコマンドレットは Disable-PSRemoting 、ローカル コンピューター上のすべての PowerShell バージョン 6 以降のセッション エンドポイント構成へのリモート アクセスをブロックします。 Windows PowerShell エンドポイントの構成には影響しません。 Windows PowerShell セッション エンドポイントの構成を無効にするには、Windows PowerShell セッション内からコマンドを実行 Disable-PSRemoting します。

すべての PowerShell バージョン 6 以降のセッション エンドポイント構成へのリモート アクセスを再度有効にするには、コマンドレットを Enable-PSRemoting 使用します。 すべての Windows PowerShell セッション エンドポイント構成へのリモート アクセスを再度有効にするには、Windows PowerShell セッション内から実行 Enable-PSRemoting します。

Note

ローカル Windows マシンへのすべての PowerShell リモート アクセスを無効にする場合は、PowerShell バージョン 6 以降のセッションと Windows PowerShell セッションの両方からこのコマンドを実行する必要があります。 Windows PowerShell は、既定ですべての Windows マシンにインストールされます。

特定のセッション エンドポイント構成へのリモート アクセスを無効にして再度有効にするには、次のコマンドレットをEnable-PSSessionConfigurationDisable-PSSessionConfiguration使用します。 個々のエンドポイントの特定のアクセス構成を設定するには、AccessMode パラメーターと共にコマンドレットを使用Set-PSSessionConfigurationします。 セッション構成の詳細については、「 about_Session_Configurations」を参照してください。

Note

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

このコマンドレットは、Windows プラットフォームでのみ使用できます。 Linux または macOS バージョンの PowerShell では使用できません。 このコマンドレットを実行するには、[管理者として実行] オプションを使用して PowerShell を起動します。

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

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

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.

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

この例では、プロンプトを表示せずに、コンピューター上のすべての 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.

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

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

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

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

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

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

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

この例では、エンドポイント構成を無効にする方法と、無効になっているエンドポイントへのループバック接続を成功させる方法を示します。 Disable-PSRemoting は、すべての 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

ローカル コンピューターへのリモート セッションの作成の最初の使用 New-PSSessionConfigurationName パラメーターは、無効な PowerShell エンドポイントを指定するために使用されます。 資格情報は、Credential パラメーターを使用してコマンドに明示的に渡されます。 この種類の接続はネットワーク スタックを通過し、ループバックではありません。 その結果、無効になっているエンドポイントへの接続試行は、Access が拒否されたエラーで失敗します。

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

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

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

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

例 6: すべての PowerShell リモート処理エンドポイント構成を無効にする

この例では、コマンドを Disable-PSRemoting 実行しても Windows PowerShell エンドポイントの構成に影響しない方法を示します。 Get-PSSessionConfiguration Windows PowerShell 内で実行すると、すべてのエンドポイント構成が表示されます。 Windows PowerShell エンドポイントの構成が無効ではないことがわかります。

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

これらのエンドポイント構成を無効にするには、 Disable-PSRemoting Windows PowerShell セッション内からコマンドを実行する必要があります。 次に、Windows PowerShell 内から実行すると、 Get-PSSessionConfiguration すべてのエンドポイント構成が無効になっていることが示されます。

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

この例では、コマンドレットによって 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
----               ----------
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すべてのFormat-Tableネットワーク ユーザーの AccessDenied セキュリティ記述子が、テスト セッション構成を含むすべてのセッション構成に追加されていることが、コマンドレットによってされます。 他のセキュリティ記述子は変更されませんが、"network_deny_all" セキュリティ記述子が優先されます。 これは、テスト セッション構成への接続に使用New-PSSessionする試行によって示されています。

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

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

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

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

パラメーター

-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

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

メモ

このコマンドレットは、Windows プラットフォームでのみ使用できます。

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

    1. WinRM サービスを停止して無効にする。
    2. 任意の IP アドレスで要求を受け入れるリスナーを削除する。
    3. WS-Management 通信用のファイアウォールの例外を無効にする。
    4. LocalAccountTokenFilterPolicy の値を 0 に復元して、リモート アクセスをコンピューターの Administrators グループのメンバーに制限する。
  • セッション エンドポイントの構成は、セッションの環境を定義する設定のグループです。 コンピューターに接続するすべてのセッションでは、コンピューターに登録されているセッション エンドポイント構成のいずれかを使用する必要があります。 すべてのセッション エンドポイント構成へのリモート アクセスを拒否することで、リモート ユーザーがコンピューターに接続するセッションを確立するのを効果的に防ぐことができます。