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 マシンにインストールされます。
特定のセッション エンドポイント構成へのリモート アクセスを無効にして再度有効にするには、 コマンドレットと Disable-PSSessionConfiguration
コマンドレットをEnable-PSSessionConfiguration
使用します。 個々のエンドポイントの特定のアクセス構成を設定するには、 コマンドレットと Set-PSSessionConfiguration
AccessMode パラメーターを使用します。 セッション構成の詳細については、「 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を実行した場合の影響
この例では、 コマンドレットと Enable-PSRemoting
コマンドレットを使用したセッション構成への影響をDisable-PSRemoting
示します。
Disable-PSRemoting
は、すべての PowerShell セッション エンドポイント構成へのリモート アクセスを無効にするために使用されます。 Force パラメーターにより、すべてのユーザー メッセージが表示されなくなります。 Get-PSSessionConfiguration
および Format-Table
コマンドレットは、コンピューター上のセッション構成を表示します。
出力は、ネットワーク トークンを持つすべてのリモート ユーザーがエンドポイント構成へのアクセスを拒否されたことを示しています。 ローカル コンピューター上の管理者グループは、ローカルに接続し (ループバックとも呼ばれます)、暗黙的な資格情報を使用している限り、エンドポイント構成へのアクセスを許可されます。
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 ...
コマンドレットを 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-PSSession
使用は、ローカル コンピューターへのリモート セッションの作成を試みます。 ConfigurationName パラメーターは、無効な 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 パラメーターには、セッション構成のアクセス許可を設定するダイアログ ボックスが表示されます。 [アクセス許可] ダイアログ ボックスで、指定されたユーザーのカスタム フル アクセス許可を作成します。
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
---- ----------
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 セッション構成を変更するために使用されます。 値が Remote の AccessMode パラメーターを使用すると、構成へのリモート アクセスが再び有効になります。
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 ...
パラメーター
-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
戻されるわけではありません。 場合によっては次の変更を手動で元に戻す必要があります。- WinRM サービスを停止して無効にする。
- 任意の IP アドレスで要求を受け入れるリスナーを削除する。
- WS-Management 通信用のファイアウォールの例外を無効にする。
- LocalAccountTokenFilterPolicy の値を 0 に復元して、リモート アクセスをコンピューターの Administrators グループのメンバーに制限する。
セッション エンドポイント構成は、セッションの環境を定義する設定のグループです。 コンピューターに接続するすべてのセッションでは、コンピューターに登録されているセッション エンドポイント構成のいずれかを使用する必要があります。 すべてのセッション エンドポイント構成へのリモート アクセスを拒否することで、リモート ユーザーがコンピューターに接続するセッションを確立するのを効果的に防ぐことができます。
関連リンク
PowerShell
A cross-platform task automation solution made up of a command-line shell and a scripting language.
フィードバック
フィードバックの送信と表示