第 1 課:開始使用 Windows PowerShell 的 Windows Server AppFabric Cmdlet

完成時間: 15 分鐘

目標: 準備 Windows PowerShell 環境,以便使用 Windows PowerShell 的 Windows Server AppFabric Cmdlet 來設定、管理與監控 Order Service 應用程式。

用途: 在此課程中,您將會載入適用於 Windows PowerShell 的 ApplicationServer 模組並啟用 Windows PowerShell 的指令碼執行。在本教學課程的其他課程中,您應該使用相同的 Windows PowerShell 主控台。

必要條件

開始此步驟之前,請先檢查下列需求:

  • 您必須已安裝 AppFabric。

  • 您必須能夠使用具有系統管理員權限的帳戶來執行 Windows PowerShell。

程序

您將會完成此課程中的下列步驟:

  1. 以系統管理認證啟動 Windows PowerShell 工作階段。

  2. 啟用 Windows PowerShell 指令碼執行。

  3. 載入適用於 Windows PowerShell 的 ApplicationServer 模組

以系統管理認證啟動 Windows PowerShell 工作階段

  1. Powershell.exe 位於 C:\Windows\System32\WindowsPowerShell\v1.0 目錄。在 [Windows 檔案總管] 中開啟該目錄,或使用搜尋工具來尋找該目錄 (按一下 [開始],然後在搜尋方塊中輸入 powershell.exe)。

  2. powershell.exe 上按一下滑鼠右鍵,然後按一下 [以系統管理員身分執行]。

  3. 當 Windows PowerShell 視窗針對您的工作階段執行之後,在標題列上按一下滑鼠右鍵,然後按一下 [內容]。

  4. 在 [“Windows PowerShell” 內容] 視窗中,確定已選取 [快速編輯模式],然後按一下 [確定]。

啟用 Windows PowerShell 中的指令碼執行

此教學課程中的大部分步驟都是使用 Windows PowerShell 工作階段。但是,您可以使用所有課程中的命令來建置指令碼以便自動化執行。在某些課程中,指令碼執行是用來簡化操作方式。在本節中,您只會針對此 Windows PowerShell 工作階段啟用本機指令碼的執行。

  1. 在 Windows PowerShell 視窗中執行下列命令,以允許在 Windows PowerShell 中執行未簽署的指令碼。

    Set-ExecutionPolicy –ExecutionPolicy RemoteSigned –Scope Process
    
  2. 當系統提示您確認執行原則變更時,請輸入 Y,然後按下 ENTER。

  3. 為確認本機指令碼執行現已啟用,請在 Windows PowerShell 中執行下列命令。

    Get-ExecutionPolicy
    

    Windows PowerShell 應該會報告 RemoteSigned 的執行原則。

–Scope Process 參數可確保原則僅針對目前的 Windows PowerShell 處理序以及您建立的任何子處理序啟用。透過使用上述命令將 Windows PowerShell 執行原則設定為 RemoteSigned,即可為目前的 Windows PowerShell 工作階段啟用下列原則:

  • 指令碼可以執行。

  • 要求從網際網路下載的指令碼與組態檔必須有來自信任的發行者的數位簽章 (包含電子郵件與即時傳訊程式)。

  • 不要求您執行以及寫入至本機電腦的指令碼 (並非從網際網路下載) 必須有數位簽章。

若要還原此原則變更,只需要關閉目前的 Windows PowerShell 工作階段與在該工作階段中啟動的任何子處理序。請注意,此教學課程中的課程要求必須為工作階段啟用已修改的執行原則。

請記住,執行原則不會防止執行任何特定命令或 Cmdlet。它只會設定指令碼與組態檔執行位置的限制。

如需有關 Windows PowerShell 2.0 之執行原則的詳細資訊,請參閱 about_execution_policies (可能為英文網頁) 或執行下列命令。

Get-help about_execution_policies

載入 AppFabric 的 Windows PowerShell 模組

  1. 執行下列命令,以使用 Windows PowerShell 的 Import-Module Cmdlet 來載入適用於 Windows PowerShell 的 ApplicationServer 模組。

    Import-Module ApplicationServer
    

    若未傳回錯誤,表示已順利載入該模組。

  2. 若要確認是否已順利載入適用於 Windows PowerShell 的 ApplicationServer 模組,請在 Windows PowerShell 視窗中執行下列命令。

    Get-Command –Module ApplicationServer
    

    此命令會以表格方式顯示適用於 Windows PowerShell 的 ApplicationServer 模組公開之所有命令的清單。

我剛剛做了什麼?

在此課程中,您使用系統管理認證啟動 Windows PowerShell,以允許在後續課程中執行指令碼。您也載入適用於 Windows PowerShell 的 ApplicationServer 模組,並確認此模組公開的命令。您將在此教學課程中使用這些命令來設定、管理與監控 Order Service 應用程式。

後續步驟

第 2 課:使用 Windows PowerShell 來部署訂單服務應用程式中,您將會使用 Windows PowerShell 建置並部署 Order Service 專案。

另請參閱

概念

第 2 課:使用 Windows PowerShell 來部署訂單服務應用程式
第 3 課:使用 Windows PowerShell 來設定 Order Service
第 4 課:使用 Windows PowerShell 來監控 Order Service
第 5 課:使用 Windows PowerShell 來追蹤工作流程

  2011-12-05