必須先在計算機上安裝和配置 Windows PowerShell 和 Windows 遠端管理 (WinRM) 的正确版本,然後才能使用 Windows PowerShell。您必須使用 Windows Management Framework,其中包含 Windows PowerShell v2 和 WinRM 2.0 的正确版本。
如果您的計算機運作的是 Windows 7 或 Windows Server 2008 R2,則不必安裝任何版本。Windows Management Framework 已經安裝。
如果您的計算機運作的是下列作業系統之一,則可以下載下傳并安裝 Windows Management Framework:
- Windows Vista Service Pack 1 (SP1) 或 Windows Vista Service Pack 2 (SP2)
- Windows Server 2008 SP1 或 Windows Server 2008 SP2
- Windows Server 2003 SP2
- Windows XP SP3
快速入門:
- 從計算機上解除安裝以前版本的 Windows PowerShell
- 從計算機上解除安裝以前版本的 WinRM
- 安裝 Windows Management Framework
- 驗證 Windows PowerShell 是否可以運作腳本
- 驗證 WinRM 是否允許 Windows PowerShell 建立連接配接
1.從計算機上解除安裝以前版本的 Windows PowerShell
必須先解除安裝 Windows PowerShell 的任何現有版本,然後才能安裝 Windows Management Framework。
注意 對于 Windows 7 或 Windows Server 2008 R2,不必執行此步驟。
從 Windows Vista 上解除安裝 Windows PowerShell
- 在“控制台”的“程式”中,打開“程式和功能”,然後解除安裝在已安裝的程式清單中出現的任何 Windows PowerShell 執行個體。例如,Windows PowerShell v2 的 Community Technology Preview (CTP) 版本可能顯示為 Windows PowerShell (TM) V2。
- 在“任務”下,選擇“檢視已安裝的更新”并解除安裝在已安裝的更新清單中出現的任何 Windows PowerShell 執行個體。例如,Windows PowerShell V1 可能作為以下某個 Microsoft 知識庫文章編号所辨別的一個 Windows 更新出現:
- KB928439
- KB923569
從 Windows Server 2008 上解除安裝 Windows PowerShell
- 啟動“伺服器管理器”,并轉到“功能”。
- 單擊“解除安裝功能”。
- 選擇“Windows PowerShell”,并按照訓示執行解除安裝。
- 在“控制台”的“程式”中,打開“程式和功能”,然後解除安裝在已安裝的程式清單中出現的任何 Windows PowerShell 執行個體。
- 在“任務”下,選擇“檢視已安裝的更新”。解除安裝在已安裝的更新清單中出現的任何 Windows PowerShell 執行個體。
從 Windows Server 2003 和 Windows XP 上解除安裝 Windows PowerShell
- 在“控制台”中,打開“添加或删除程式”,然後解除安裝在已安裝的程式清單中出現的任何 Windows PowerShell 執行個體。
- 在“添加或删除程式”中,選擇“顯示更新”。解除安裝在已安裝的更新清單中出現的任何 Windows PowerShell 執行個體。例如,Windows PowerShell V1 可能作為知識庫文章編号 KB926139 所辨別的 Windows 更新出現。
2.從計算機上解除安裝以前版本的 WinRM
從 Windows Vista 或 Windows Server 2008 上解除安裝 WinRM
- 在“控制台”的“程式”中,打開“程式和功能”,然後解除安裝在已安裝的程式清單中出現的 Windows 遠端管理的任何執行個體。
- 在“任務”下,選擇“檢視已安裝的更新”。解除安裝在已安裝的更新清單中出現的 Windows 遠端管理的任何執行個體。例如,WinRM 2.0 的 Community Technology Preview (CTP) 可能作為以下某個知識庫文章編号所辨別的 WindowsRemoteManagement 出現:
- KB936059
- KB950099
- 在“控制台”中,打開“添加或删除程式”,然後解除安裝在已安裝的程式清單中出現的 Windows 遠端管理的任何執行個體。
- 在“添加或删除程式”中,選擇“顯示更新”。解除安裝在已安裝的更新清單中出現的 Windows 遠端管理的任何執行個體。例如,WinRM 可能作為知識庫文章編号 KB936059 所辨別的 Windows 更新出現。
3.安裝 Windows Management Framework
-
下載下傳并安裝
Windows Management Framework。選擇包含 Windows PowerShell v2 和 WinRM 2.0 且應用于您的作業系統、系統體系結構和語言的程式包。
安裝 WinRM 和 Windows PowerShell 之後,按照後續步驟中的介紹配置該軟體,使其能夠正常工作。
注意 如果您的本地計算機受 Microsoft Internet Security and Acceleration (ISA) 伺服器保護,則您可能必須在該計算機上安裝 Windows 防火牆用戶端或配置一個代理伺服器,才能将 Windows PowerShell 連接配接到基于雲的服務。有關詳細資訊,請參閱
Windows PowerShell:管理者常見問題。
4.驗證 Windows PowerShell 是否可以運作腳本
- 單擊“開始”>“所有程式”>“附件”>“Windows PowerShell”。
- 執行以下操作之一以打開 Windows PowerShell:
- 如果運作的是 Windows Vista、Windows 7 或 Windows Server 2008 R2,請右鍵單擊“Windows PowerShell”并選擇“以管理者身份運作”。當出現詢問您是否要繼續的使用者帳戶控制提示時,請選擇“繼續”。
- 如果運作的是 Windows XP 或 Windows Server 2003,請單擊“Windows PowerShell”。
-
運作以下指令:
複制
Get-ExecutionPolicy
- 如果傳回的值是除
以外的任何其他值,則必須将該值更改為RemoteSigned
RemoteSigned
。
注意 若将腳本執行政策設定為
,則隻能運作在您的計算機上建立的腳本或由受信任的源簽名的腳本。RemoteSigned
使腳本能夠在 Windows PowerShell 中運作
Set-ExecutionPolicy RemoteSigned
5.驗證 WinRM 是否允許 Windows PowerShell 建立連接配接
- 單擊“開始”>“所有程式”>“附件”。
- 執行以下操作之一以打開指令提示符:
- 如果運作的是 Windows Vista、Windows 7 或 Windows Server 2008 R2,請右鍵單擊“指令提示符”并選擇“以管理者身份運作”。當出現詢問您是否要繼續的使用者帳戶控制提示時,請選擇“繼續”。
- 如果運作的是 Windows XP 或 Windows Server 2003,請單擊“指令提示符”。
- 在指令提示符下,運作以下指令:
注意 如果 WinRM 服務已在運作,則不必啟動它。可以通過運作net start winrm winrm get winrm/config/client/auth
指令檢查 WinRM 服務的狀态。sc query winrm
- 在結果中查找值
。如果此值為Basic =
,則必須将此值更改為Basic = false
注意 如果您已啟動 WinRM 服務并且無需更改Basic = true
值,請運作Basic
指令來停止 WinRM 服務。net stop winrm
将 WinRM 配置為支援基本身份驗證
- 在您剛剛以管理者身份打開的指令提示符下,運作以下指令。大括号
之間的值區分大小寫:{ }
winrm set winrm/config/client/auth @{Basic="true"}
- 在指令輸出中,驗證值
注意 如果您已啟動 WinRM 服務,請運作Basic = true
net stop winrm