檢視和執行 Windows PowerShell 指令碼

適用於: Virtual Machine Manager 2008, Virtual Machine Manager 2008 R2, Virtual Machine Manager 2008 R2 SP1

如果您在 VMM 程式庫中存放 Windows PowerShell 指令碼,便可以在 [程式庫] 檢視中檢視、編輯以及執行指令碼。

若要從 VMM 系統管理員主控台執行指令碼,您必須在本機電腦上的 Windows PowerShell 中啟用指令碼。在預設情況下,Windows PowerShell 中不允許指令碼。如需詳細資訊,請參閱 Windows PowerShell 關於說明主題中的 about_Signing (https://go.microsoft.com/fwlink/?LinkId=119744),或在 Windows PowerShell 中輸入下列指令程式:Get-Help about_Signing.

從 VMM 程式庫檢視或編輯 Windows PowerShell 指令碼

  1. 在 [程式庫] 檢視中,選取您想要檢視的指令碼。

  2. 在 [動作] 窗格的 [指令碼] 下方,按一下 [檢視 PowerShell 指令碼] 便會在 [記事本] 開啟指令碼。

    如果您使用 [另存新檔] 在同一個共用上儲存新的指令碼,該指令碼會在下一次程式庫重新整理時新增至程式庫。副檔名為 .ps1 的檔案可讓您在 Windows Powershell – Virtual Machine Manager 命令殼層中執行。如果您不想要等到下一次程式庫重新整理,可以使用 [重新整理共用] 動作,對程式庫共用執行手動重新整理。

從 VMM 程式庫執行 Windows PowerShell 指令碼

  1. 在 [程式庫] 檢視中,選取您想要執行的指令碼。

  2. 在 [動作] 窗格的 [指令碼] 下方,按一下 [執行 PowerShell 指令碼],便會在 Windows PowerShell Runspace 載入指令碼。

  3. 如果您在執行未簽署的指令碼,請在命令提示字元輸入 R (執行一次)。

另請參閱

概念

使用 Windows PowerShell - VMM 命令殼層
如何執行手動程式庫重新整理

其他資源

如何將檔案新增至程式庫
設定 VMM 程式庫
Virtual Machine Manager 中的指令碼簡介
VMM 2008 R2 指令碼的新功能