使用整合模組

重要

此版本的服務管理自動化 (SMA) 已終止支援。 我們建議您 升級至 SMA 2022

整合模組是包含 Windows PowerShell 模組的套件。 如需撰寫 Windows PowerShell 模組的資訊,請參閱 撰寫 Windows PowerShell 模組(英文)。 整合模組可以包含 Windows PowerShell 模組(英文) 中指定的任何有效的模組類型。 這包括指令碼模組 (.psm1)、二進位模組 (.dll) 與資訊清單模組 (.psd1)。 整合模組封裝是與模組同名的壓縮檔案,並有 .zip 副檔名。 它包含也具有模組名稱的單一資料夾。 Windows PowerShell 模組和任何支援的檔案,包括資訊清單檔案 (.psd1) (如果模組有一個),都必須包含在此資料夾中。

如果模組應該包含 Connection 類型,它也必須包含名稱 <為 ModuleName> 的檔案-Automation.json,指定連接類型屬性。 這是具有下列格式的 json 檔案。

{
   "ConnectionFields": [
   {
      "IsEncrypted":  false,
      "IsOptional":  false,
      "Name":  "ComputerName",
      "TypeName":  "System.String"
   },
   {
      "IsEncrypted":  false,
      "IsOptional":  true,
      "Name":  "Username",
      "TypeName":  "System.String"
   },
   {
      "IsEncrypted":  true,
      "IsOptional":  false,
      "Name":  "Password",
   "TypeName":  "System.String"
   }],
   "ConnectionTypeName":  "DataProtectionManager",
   "IntegrationModuleName":  "DataProtectionManager"
}

建立和使用自動化 Runbook 的步驟會根據您使用管理入口網站或 Windows PowerShell 而有所不同。 下列各節提供使用這兩種方法之各種常見作業的基本步驟。

列舉已安裝的模組

取得管理入口網站中已安裝模組的清單

  1. 選取 [自動化] 工作區。

  2. 如果您使用 Azure,請選取自動化帳戶。

  3. 在視窗頂端,選取 [ 資產]。

  4. 使用 模組類型檢查清單中的資產。

使用 Windows PowerShell 取得已安裝模組的清單

下列範例命令會擷取自動化中安裝的所有模組。

$webServer = 'https://MyWebServer'
$port = 9090
Get-SmaModule -WebServiceEndpoint $webServer -Port $port

匯入模組

模組是包含資料夾之 .zip 擴展名的壓縮檔,其中包含下列其中一種檔類型:

  • 模組 (psm1 檔)
  • 模組資訊清單 (psd1 檔)

使用管理入口網站匯入模組

  1. 選取 [自動化] 工作區。

  2. 在視窗底部,選取 [匯入 模組]。

  3. 選取 [瀏覽檔案]。

  4. 選取模組檔案,然後選取 [確定]。

  5. 選取對話框上的複選標記按鈕。

使用 Windows PowerShell 匯入模組

下列範例命令可顯示如何匯入模組。

$webServer = 'https://MyWebServer'
$port = 9090
$modulePath = 'C:\Modules\MyModule.psm1'
Import-SmaModule -WebServiceEndpoint $webServer -Port $port -Path $modulePath

列舉 amModule 中的活動

取得管理入口網站模組中的活動清單

  1. 選取 [自動化] 工作區。

  2. 如果您使用 Azure,請選取自動化帳戶。

  3. 在視窗頂端,選取 [ 資產]。

  4. 找出模組並加以選取。

  5. 捲動至 [模組詳細資訊] 畫面的底部,並檢查其活動。

  6. 您可以選擇性地選取放大鏡圖示,以篩選特定活動。

使用 Windows PowerShell 取得課程模組中的活動清單

下列範例命令可顯示如何擷取特殊模組中的活動。

$webServer = 'https://MyWebServer'
$port = 9090
$moduleName = 'MyModule'
$module = Get-SmaModule -WebServiceEndpoint $webServer -Port $port -Name $moduleName
$module.Activities

使用 Windows PowerShell 取得所有模組中的活動清單

下列範例命令示範如何擷取自動化中安裝的所有模組中的活動。

$webServer = 'https://MyWebServer'
$port = 9090
$modules = Get-SmaModule -WebServiceEndpoint $webServer -Port $port
$modules | foreach {$_.Activities} | sort Name,ModuleName | ft Name,ModuleName,Description

下一步