通過 COM 從 Orchestrator 中獲得更深入的訊息


我們發現很多用戶會利用 Orchestrator 來獲得一些有關安裝過程的內部工作機制的訊息,而這些訊息都是無法通過 Web 服務所獲得的。Web 服務可讓您檢索有關以下內容的資訊:

•    文件夾

•    Runbook

•    Runbook 參數

•    活動

•    作業

•    Runbook 實例

•    Runbook 實例參數

•    活動實例

•    活動實例數據

•    Runbook 服務器

•    Runbook 關系圖

•    統計訊息

•    事件

除了開始和停止作業外,其他所有通過 Web 服務所獲得的內容都是唯讀的。但是,用戶希望能夠編寫和修改,並執行類似於以下的操作:

•    查看並修改變量和計數器

•    查看安裝了哪些集成包

•    查看日誌歷史記錄

•    導出或導入 Runbook

•    簽入或簽出(或取消簽出)Runbook

•    查看哪位用戶擁有連接到 Management Server 的 Runbook Designer

這些功能,以及更多功能均可於 Orchestrator COM 介面使用。我們將撰寫一篇新的文章來解釋如何連接到 COM 介面,並使用該介面來進行多個有助於您進一步自動化與 Orchestrator 交互的操作。由於使用 C# 代碼進行編寫和編譯更為簡單,我們將在這些範例中使用 PowerShell。

首先,先打開一個 PowerShell (x86) ISE(這是因為 Orchestrator 2012 為 64 位軟體)。請注意,在這一範例中,您將需要在 Orchestrator Management Server 上進行操作。

使用以下命令在 PowerShell 中創建一個新項目:

$oismgr = new-object -com OpalisManagementService.OpalisManager

可以從這裡查看到 COM 的內容,以及所有可用的方法列表(這些方法的數量很多!):

$oismgr | gm

   TypeName: System.__ComObject#{9b7ffff7-3ac0-40ce-b2ae-99514a43307e}

$oismgr | gm


   TypeName: System.__ComObject#{9b7ffff7-3ac0-40ce-b2ae-99514a43307e}

Name                                    MemberType Definition                                                                                   
----                                    ---------- ----------                                                                                   
AccessCheck                             Method     void AccessCheck (int, string, int, string, Variant)                                         
AddFolder                               Method     void AddFolder (int, string, Variant)                                                        
AddIntegrationPack                      Method     void AddIntegrationPack (int, Variant)                                                       
AddPolicy                               Method     void AddPolicy (int, string, Variant)                                                        
AddResource                             Method     void AddResource (int, string, Variant)                                                      
AddUserToRuntimeRole                    Method     void AddUserToRuntimeRole (int, string)                                                      
ChangeLicense                           Method     void ChangeLicense (string, string)                                                          
CheckIn                                 Method     void CheckIn (int, string, string, string)                                                   
CheckOut                                Method     void CheckOut (int, string, string, Variant)                                                 
ClientConnectSignal                     Method     void ClientConnectSignal (Variant)                                                           
ConfigureActionServer                   Method     void ConfigureActionServer (int, string, Variant)                                            
Connect                                 Method     void Connect (string, string, Variant)                                                       
CreatePolicyRequest                     Method     void CreatePolicyRequest (int, string, int, string, string, string, string, Variant, Variant)
DeleteEvent                             Method     void DeleteEvent (int, string)                                                               
DeleteFolder                            Method     void DeleteFolder (int, string, int)                                                         
DeleteLogEntry                          Method     void DeleteLogEntry (int, string, string)                                                    
DeleteObject                            Method     void DeleteObject (int, string, string, int)                                                 
DeletePolicy                            Method     void DeletePolicy (int, string, int)                                                         
DeletePolicyImages                      Method     void DeletePolicyImages (Variant)                                                            
DeleteResource                          Method     void DeleteResource (int, string, string)                                                    
Disconnect                              Method     void Disconnect (int, string)                                                                
DoesPolicyExist                         Method     void DoesPolicyExist (string)                                                                
Find                                    Method     void Find (int, string, int, string, string, Variant)                                        
FindPoliciesWithoutImages               Method     void FindPoliciesWithoutImages (int, Variant)                                                
GetActionServers                        Method     void GetActionServers (int, string, Variant)                                                 
GetActionServerTypes                    Method     void GetActionServerTypes (int, Variant)                                                     
GetAuditHistory                         Method     void GetAuditHistory (int, string, string, string, Variant)                                  
GetCheckOutStatus                       Method     void GetCheckOutStatus (int, string, Variant)                                                
GetClientConnections                    Method     void GetClientConnections (int, Variant)                                                     
GetConfigurationIds                     Method     void GetConfigurationIds (int, Variant)                                                      
GetConfigurationValues                  Method     void GetConfigurationValues (int, string, Variant)                                           
GetCountersValueAndMarker               Method     void GetCountersValueAndMarker (Variant)                                                     
GetCustomStartParameterName             Method     void GetCustomStartParameterName (string, Variant)                                           
GetCustomStartParameters                Method     void GetCustomStartParameters (Variant)                                                      
GetDatastoreType                        Method     void GetDatastoreType (int)                                                                  
GetEventDetails                         Method     void GetEventDetails (string, Variant)                                                       
GetEvents                               Method     void GetEvents (Variant)                                                                     
GetFolderContents                       Method     void GetFolderContents (int, string, Variant)                                                
GetFolderPathFromID                     Method     void GetFolderPathFromID (string, Variant)                                                   
GetFolders                              Method     void GetFolders (int, string, Variant)                                                       
GetInstanceStatusForRequests            Method     void GetInstanceStatusForRequests (int, Variant, Variant, Variant)                           
GetIntegrationPacks                     Method     void GetIntegrationPacks (int, Variant)                                                      
GetLatestPolicyReturnDataDefinition     Method     void GetLatestPolicyReturnDataDefinition (string, Variant, Variant)                          
GetLicenseExpirationTime                Method     void GetLicenseExpirationTime (string)                                                       
GetLicenseInformation                   Method     void GetLicenseInformation (int, string, Variant)                                            
GetLogHistory                           Method     void GetLogHistory (int, string, int, Variant)                                               
GetLogHistoryObjectDetails              Method     void GetLogHistoryObjectDetails (int, string, string, string, Variant)                       
GetLogHistoryObjects                    Method     void GetLogHistoryObjects (int, string, string, Variant)                                     
GetLogObjectDetails                     Method     void GetLogObjectDetails (int, string, string, string, Variant)                              
GetObjectSecurity                       Method     void GetObjectSecurity (int, string, Variant)                                                
GetObjectTypes                          Method     void GetObjectTypes (int, Variant)                                                           
GetPolicyIDFromPath                     Method     void GetPolicyIDFromPath (string, Variant)                                                   
GetPolicyInputParameterId               Method     void GetPolicyInputParameterId (int, string, string, string)                                 
GetPolicyObjectList                     Method     void GetPolicyObjectList (int, string, Variant)                                              
GetPolicyPathFromID                     Method     void GetPolicyPathFromID (string, Variant)                                                   
GetPolicyPublishState                   Method     void GetPolicyPublishState (int, string, int)                                                
GetPolicyRunningState                   Method     void GetPolicyRunningState (Variant, Variant)                                                
GetPolicyRunStatus                      Method     void GetPolicyRunStatus (int, string, Variant)                                               
GetProductKey                           Method     void GetProductKey (string)                                                                  
GetRequestOutputData                    Method     void GetRequestOutputData (int, Variant, Variant, Variant)                                   
GetResources                            Method     void GetResources (int, string, string, Variant)                                             
GetRunbookTesterPublishedRequests       Method     void GetRunbookTesterPublishedRequests (int, Variant)                                        
GetVersionInformation                   Method     void GetVersionInformation (Variant)                                                         
Initialize                              Method     void Initialize ()                                                                           
IsPolicyRunning                         Method     void IsPolicyRunning (int, string)                                                           
LoadObject                              Method     void LoadObject (int, string, Variant)                                                       
LoadPolicy                              Method     void LoadPolicy (int, string, Variant)                                                       
LoadResource                            Method     void LoadResource (int, string, Variant)                                                     
ModifyFolder                            Method     void ModifyFolder (int, string, Variant)                                                     
ModifyObject                            Method     void ModifyObject (int, string, string, Variant)                                             
ModifyPolicy                            Method     void ModifyPolicy (int, string, Variant, Variant)                                            
ModifyResource                          Method     void ModifyResource (int, string, Variant)                                                   
MoveObject                              Method     void MoveObject (int, string, string, string)                                                
PolicyHasMonitor                        Method     void PolicyHasMonitor (int, string, Variant)                                                 
RemoveClientConnection                  Method     void RemoveClientConnection (string)                                                         
RemoveIntegrationPack                   Method     void RemoveIntegrationPack (int, Variant)                                                    
RemoveSatellite                         Method     void RemoveSatellite (string)                                                                
Replace                                 Method     void Replace (int, string, int, string, string, string, Variant)                             
RetrievePoliciesLinkedToAS              Method     void RetrievePoliciesLinkedToAS (string, Variant)                                            
SetConfigurationValues                  Method     void SetConfigurationValues (int, string, Variant)                                           
SetLicenseInformation                   Method     void SetLicenseInformation (int, string, Variant)                                            
SetObjectSecurity                       Method     void SetObjectSecurity (int, string, string)                                                 
SetPolicyImage                          Method     void SetPolicyImage (int, string, int, Variant)                                              
SetPolicyPublishState                   Method     void SetPolicyPublishState (int, string, int)                                                
SetPolicyPublishStateWithParams         Method     void SetPolicyPublishStateWithParams (int, string, int, string)                              
SetPolicyPublishStateWithParamsAndGetID Method     void SetPolicyPublishStateWithParamsAndGetID (int, string, int, string, Variant)             
SetReportingOptions                     Method     void SetReportingOptions (int, string)                                                       
StartSqmNotification                    Method     void StartSqmNotification ()                                                                 
UndoCheckOut                            Method     void UndoCheckOut (int, string, int, Variant)                                                
UpdateClientActivity                    Method     void UpdateClientActivity (string, string)

很遺憾,其他地方都沒有記錄這些方法,因此有時您需要進行多次嘗試才能正常運行,幸運的是,我們將為您避免這些麻煩。在使用 COM 介面時,Orchestrator 中的安全模式仍然有效,而且您需要擁有管理員權限才能使用其中很多功能,因此,這實際上稍微提高了 Orchestrator 的限制程度,而這對於用戶而言將是一條好消息。而且大多數操作需要用戶(通過連接方法)建立一個連接控制代碼,但是用戶也可在不進行連接的情況下使用其他方法(如 GetEvents)。此處所顯示的一些介面並未真正執行,或可從外部代碼中查詢。

為了向您展示這些內容的工作原理,我們將從不需要任何連接控制代碼就可以運行的 GetEvents 開始。對於許多方法而言,它們需要在一個對象周圍設置一個 “可變包裝”,以創立該方法所預期的 “可變” 類型。此外,您還將經常在一個將成為該方法輸出的引用變量中傳遞,而非只是在 HResult 程式碼的 “返回值” 中傳遞。

        $oismgr = new-object -com OpalisManagementService.OpalisManager
        $oevents = New-Object object
        $events = $events = New-Object Runtime.InteropServices.VariantWrapper($oevents)
        $oismgr.GetEvents([ref]$events)
        $xml = [XML]$events
        $xml.OuterXml

該方法將輸出類似於以下內容的程式碼(我們編排了該 XML 的格式,以更易於您查看):

<Events>
  <Event>
    <UniqueID>{09A4CEEE-8EBE-4D1C-B5DD-06DA3EBCE01A}</UniqueID>
    <Type>Information</Type>
    <Computer></Computer>
    <Summary>Completed Log Cleanup</Summary>
    <DateTime>
      129782594190000000
    </DateTime>
  </Event>
</Events>

因此,您可發現從 COM 介面中獲取訊息相對而言會簡單很多。當然,我們更願意從 Web 服務中獲取諸如事件之類的訊息,因此這樣更容易處理。現在,一起來看看將如何執行需要憑據和連接的操作。將第一個參數顯示為一個 int 的任何方法基本上都需要連接。例如,GetIntegrationPacks 方法。以下 PowerShell 範例將使用連接方法來為 COM 介面創建一個連接控制代碼,並返回一個包含連接 ID 的整數。($Username 為 “<domain>\<username>”)

            $oismgr = new-object -com OpalisManagementService.OpalisManager
            $ohandle = New-Object object
            $handle = $handle = New-Object Runtime.InteropServices.VariantWrapper($ohandle)
            $retval = $oismgr.Connect($UserName, $password, [ref]$handle)
            $handle

然後,您將使用該控制代碼 ID 作為該“需要連接”方法的第一個參數,如下:

            $odetails = new-object object
            $ipdetails = $evdetails = New-Object Runtime.InteropServices.VariantWrapper($odetails)
            $retval = $oismgr.GetIntegrationPacks($Handle, [ref]$ipdetails)
            $output = [XML]$ipdetails
            $output.OuterXml

上述程式碼將產生類似於以下的 XML:

<IntegrationPacks>
  <IntegrationPack>
    <UniqueIDdatatype="string">{12A45CB8-39DE-43A7-8FA2-E90379A5091F}</UniqueID>
    <Namedatatype="string">System Center Integration Pack for Microsoft .NET Framework Activities</Name>
    <Descriptiondatatype="string">Activities for Orchestrator Integration Toolkit for Microsoft .NET</Description>
    <Versiondatatype="int64">7</Version>
    <Librarydatatype="string">Microsoft.SystemCenter.Orchestrator.Integration.Toolkit.IP.ServerExtension.dll</Library>
    <ProductNamedatatype="string">{12A45CB8-39DE-43a7-8FA2-E90379A5091F}.OIP</ProductName>
    <ProductIDdatatype="string">{E88EF9F3-448F-49DC-BF02-2C93BFC8BB29}</ProductID>
  </IntegrationPack>
</IntegrationPacks>

正如您可看到的,獲得這些消息將十分容易。實際上,我們編寫了一個 PowerShell 範例,該範例可在您將資訊導入之前先驗證 Runbook,以確保 Runbook 中所含的活動實際上已安裝,並作為 IP 中的一部分。

希望您能享受編碼的過程!:)

本文原始發布於 通过 COM 从 Orchestrator 中获得更深入的信息

Comments (0)

Skip to main content