防止電腦接收遠端 Windows PowerShell 命令。
語法
Disable-PSRemoting [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]
描述
Disable-PSRemoting 函數會將「全部拒絕」項目新增至安全性描述元,藉以停用本機電腦上的所有工作階段設定。這樣會防止本機電腦接收遠端命令。
Disable-PSRemoting 不會停止 WinRM 服務,也不會防止本機電腦的使用者建立連線到遠端電腦的工作階段或傳送命令至其他電腦。
若要重新啟用工作階段設定,請使用 Enable-PSRemoting 或 Enable-PSSessionConfiguration Cmdlet。
若要在 Windows Vista、Windows Server 2008 和更新版的 Windows 上執行這個函數,您必須使用 [以系統管理員身分執行] 選項開啟 Windows PowerShell。
參數
-Force
抑制所有使用者提示。根據預設,系統會要求您確認每項作業。
必要? |
false |
位置? |
named |
預設值 |
False |
接受管線輸入? |
false |
接受萬用字元? |
false |
-Confirm
在執行命令前先提示確認。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
false |
接受萬用字元? |
false |
-WhatIf
說明執行命令時將會發生何種情況,但不會實際執行命令。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
false |
接受萬用字元? |
false |
<CommonParameters>
這個 Cmdlet 支援一般參數:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。如需詳細資訊,請參閱 about_Commonparameters.
輸入和輸出
輸入型別是可經由管道輸出至 Cmdlet 的物件型別。傳回型別則是 Cmdlet 所傳回的物件型別。
輸入 |
None 您無法經由管道將輸入輸出至這個 Cmdlet。 |
輸出 |
None 這個 Cmdlet 不會傳回任何物件。 |
附註
工作階段設定是指定義工作階段環境的一組設定。工作階段設定位於遠端電腦上,而且由連線到該電腦的本機和遠端工作階段使用。
連線到電腦的每個工作階段都必須使用已在電腦上註冊的其中一個工作階段設定。這包括您使用 New-PSSession 或 Enter-PSSession Cmdlet 建立的固定工作階段,以及在使用利用 WS-Management 遠端技術之 Cmdlet (例如 Invoke-Command) 的 ComputerName 參數時,Windows PowerShell 所建立的暫存工作階段。透過拒絕所有工作階段設定的存取,您就可以有效地防止所有使用者建立連線到電腦的工作階段。
Disable-PSRemoting 的作用相當於 "Disable-PSSessionConfiguration -name *"。
範例 1
C:\PS>disable-psremoting 描述 ----------- 這個命令會停用電腦上的所有工作階段設定。
範例 2
C:\PS>disable-psremoting -force 描述 ----------- 這個命令會停用電腦上的所有工作階段設定,而不進行提示。
範例 3
C:\PS>disable-psremoting -force C:\PS> new-pssession -computername localhost [localhost] Connecting to remote server failed with the following error message : Access is denied. For more information, see the about_Remote_Troub leshooting Help topic. + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException + FullyQualifiedErrorId : PSSessionOpenFailed C:\PS> new-pssession -computername Server01 Id Name ComputerName State Configuration Availability -- ---- ------------ ----- ------------- ------------ 1 Session1 Server01... Opened Microsoft.PowerShell Available C:\PS> enable-pssessionConfiguration -name * -force C:\PS> new-pssession -computername localhost Id Name ComputerName State Configuration Availability -- ---- ------------ ----- ------------- ------------ 1 Session1 localhost Opened Microsoft.PowerShell Available 描述 ----------- 這個範例會示範使用 Disable-PSRemoting 的作用。 第一個命令會使用 Disable-PSRemoting 來停用本機電腦上所有已註冊的工作階段設定。 第二個命令會使用 New-PSSession 來建立本機電腦的遠端工作階段 (也稱為「回送」)。因為工作階段所需的工作階段設定已停用,所以此命令會失敗。 第三個命令會使用 New-PSSession Cmdlet 來建立從本機電腦連線到 Server01 遠端電腦的工作階段。這個命令 (使用遠端電腦上的工作階段設定) 將會成功。 第四個命令會使用 Enable-PSSessionConfiguration Cmdlet 來重新啟用本機電腦上的所有工作階段設定。此命令會在 Name 參數中使用 * (全部) 值。 第五個命令會嘗試再次使用 New-PSSession Cmdlet 來建立回送工作階段。此時,命令將會成功,因為所需的工作階段設定已啟用。
範例 4
C:\PS>disable-psremoting -force C:\PS> get-psSessionConfiguration | format-table -property name, permission -auto Name Permission ---- ---------- microsoft.powershell Everyone AccessDenied, BUILTIN\Administrators AccessAllowed microsoft.powershell32 Everyone AccessDenied, BUILTIN\Administrators AccessAllowed C:\PS> enable-psremoting -force WinRM already is set up to receive requests on this machine. WinRM already is set up for remote management on this machine. C:\PS>> Get-PSSessionConfiguration | ft name, Permission -auto Name Permission ---- ---------- microsoft.powershell BUILTIN\Administrators AccessAllowed microsoft.powershell32 BUILTIN\Administrators AccessAllowed 描述 ----------- 這個範例會示範使用 Disable-PSRemoting 和 Enable-PSRemoting 之工作階段設定的作用。 第一個命令會使用 Disable-PSRemoting 函數來停用所有已註冊的工作階段設定。Force 參數會抑制所有使用者提示。 第二個命令會使用 Get-PSSessionConfiguration Cmdlet 來顯示電腦上已註冊的工作階段設定。此命令會使用管線運算子,將結果傳送至 Format-Table 命令,以便僅在表格中顯示設定的 Name 和 Permission 屬性。 產生的表格顯示拒絕所有人的設定存取權限。 第三個命令會使用 Enable-PSRemoting Cmdlet 來重新啟用電腦上的所有工作階段設定。您也可以使用 "Enable-PsSessionConfiguration -name *" 命令。此命令會使用 Force 參數來抑制所有使用者提示並且重新啟動 WinRM 服務,而不進行提示。 第四個命令會使用 Get-PSSessionConfiguration 和 Format-Table 來顯示工作階段設定的名稱和權限。結果顯示,Administrators 群組的成員現在擁有工作階段設定的存取權。
請參閱