通过 COM 从 Orchestrator 中获得更深入的信息
我发现很多用户请求利用 Orchestrator 来创建集成,以获得一些有关某一安装过程的内部工作机制的信息,而这些信息都是无法通过 Web 服务所获得的。Web 服务可让您检索有关以下内容的信息:
- 文件夹
- Runbook
- Runbook 参数
- 活动
- 作业
- Runbook 实例
- Runbook 实例参数
- 活动实例
- 活动实例数据
- Runbook 服务器
- Runbook 关系图
- 统计信息
- 事件
除了开始作业和停止作业以外,其他所有通过 Web 服务所获得的内容都是只读的。但是,用户还希望能够进行编程操作(和修改操作),并执行类似于以下的操作:
- 查看并修改变量和计数器
- 查看安装了哪些集成包
- 查看日志历史记录
- 导出或导入 Runbook
- 签入或签出(或取消签出)Runbook
- 查看哪位用户拥有连接到 Management Server 的 Runbook Designer
所有这些功能,以及更多功能均已通过 Orchestrator COM 界面可用。我将撰写一篇新的文章来解释如何连接到 COM 界面,并使用该界面来进行多个有助于您进一步自动化与 Orchestrator 交互的操作。由于使用 C# 代码进行编写和编译更为简单(对我而言这比使用 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}
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 中的一部分,从而您无需导入 Runbook,并获得不必要的“未知”活动。…
今后我将继续这一博文系列,向您介绍有关如何在 COM 界面中使用更多方法的信息。希望您届时您能享受编码的过程!:)
Comments
- Anonymous
April 28, 2015
我們發現很多用戶會利用 Orchestrator 來獲得一些有關安裝過程的內部工作機制的訊息,而這些訊息都是無法通過 Web 服務所獲得的。Web 服務可讓您檢索有關以下內容的資訊:
•