使用整合模組Work with integration modules

重要

此版本的 Service Management Automation (SMA) 已達終止支援,建議您 升級至 SMA 2019This version of Service Management Automation (SMA) has reached the end of support, we recommend you to upgrade to SMA 2019.

整合模組是包含Windows PowerShell 模組的套件。An Integration Module is a package that contains a Windows PowerShell Module. 如需撰寫 Windows PowerShell 模組的資訊,請參閱 撰寫 Windows PowerShell 模組(英文)。For information on writing a Windows PowerShell Module, see Writing a Windows PowerShell Module. 整合模組可以包含 Windows PowerShell 模組(英文) 中指定的任何有效的模組類型。An Integration Module can contain any of the valid Module Types specified in Windows PowerShell Modules. 這包括指令碼模組 (.psm1)、二進位模組 (.dll) 與資訊清單模組 (.psd1)。This includes Script Modules (.psm1), Binary Modules (.dll), and Manifest Modules (.psd1). 整合模組封裝是與模組同名的壓縮檔案,並有 .zip 副檔名。The Integration Module package is a compressed file with the same name as the module and a .zip extension. 它包含也具有模組名稱的單一資料夾。It contains a single folder also with the name of the module. Windows PowerShell 模組和任何支援的檔案,包括資訊清單檔案 (.psd1) (如果模組有一個),都必須包含在此資料夾中。The Windows PowerShell module and any supporting files, including a manifest file (.psd1) if the module has one, must be contained in this folder.

如果模組應該包含 連接 類型,它也必須包含名稱為 <ModuleName >-Automation.js的檔案,以指定連線類型屬性。If the module should contain a Connection type, it must also contain a file with the name <ModuleName>-Automation.json that specifies the connection type properties. 這是具有下列格式的 json 檔案。This is a json file with the following format.

{
   "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"
}

根據您使用的是入口網站或 Windows PowerShell,建立和使用自動化 runbook 的步驟會有所不同。The steps for creating and working with Automation runbooks are different depending on whether you using a management portal or Windows PowerShell. 以下各節提供使用這兩種方法進行各種一般作業的基本步驟。The basic steps for various common operations using both methods are provided in the following sections.

列舉已安裝的模組Enumerate installed modules

在管理入口網站中取得已安裝的模組清單Get a list of installed modules in the management portal

  1. 選取 [自動化]**** 工作區。Select the Automation workspace.

  2. 若是使用 Azure,請選取自動化帳戶。If you are using Azure, then select an Automation account.

  3. 在視窗頂端,按一下 [資產]****。At the top of the window, click Assets.

  4. 使用 模組類型檢查清單中的資產。Inspect the assets in the list with a Type of Module.

使用 Windows PowerShell 取得已安裝模組的清單Get a list of installed modules using Windows PowerShell

下列範例命令會取出自動化中安裝的所有模組。The following sample commands retrieve all modules installed in Automation.

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

匯入模組Import a module

模組是一種副檔名為 .zip 的壓縮檔,其中具有資料夾且內含下列其中一種檔案類型:A module is a compressed file with a .zip extension that contains a folder which includes one of the following file types:

  • 模組 (psm1 檔)A module (psm1 file)
  • 模組資訊清單 (psd1 檔)A module manifest (psd1 file)

使用入口網站匯入模組Import a module using the management portal

  1. 選取 [自動化] 工作區。Select the Automation workspace.

  2. 在視窗底部,按一下 [匯入模組]。At the bottom of the window, click Import Module.

  3. 按一下 [瀏覽檔案]。Click Browse for File.

  4. 選取模組檔案並按一下 [確定]。Select the module file and click OK.

  5. 按一下對話方塊中的核取記號按鈕。Click the checkmark button on the dialog box.

使用 Windows PowerShell 匯入模組Import a module using Windows PowerShell

下列範例命令可顯示如何匯入模組。The following sample commands show how to import a module.

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

列舉 amModule 中的活動Enumerate activities in amModule

在入口網站中取得模組中的活動清單Get a list of activities in a module in the management portal

  1. 選取 [自動化] 工作區。Select the Automation workspace.

  2. 若是使用 Azure,請選取自動化帳戶。If you are using Azure, then select an Automation account.

  3. 在視窗頂端,按一下 [資產]。At the top of the window, click Assets.

  4. 找出模組並加以選取。Locate the module and select it.

  5. 捲動至 [模組詳細資訊] 畫面的底部,並檢查其活動。Scroll to the bottom of the Module Details screen and inspect its activities.

  6. 您也可以選擇按一下放大鏡圖示以篩選出特殊活動。Optionally, click the magnifying glass icon to filter for particular activities.

使用 Windows PowerShell 取得模組中的活動清單Get a list of activities in a module using Windows PowerShell

下列範例命令可顯示如何擷取特殊模組中的活動。The following sample commands show how to retrieve the activities in a particular module.

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

使用 Windows PowerShell 取得所有模組中的活動清單Get a list of activities in all modules using Windows PowerShell

下列範例命令示範如何在自動化中安裝的所有模組中取得活動。The following sample commands show how to retrieve the activities in all modules installed in Automation.

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

後續步驟Next steps