超酷工具:用于启动 Runbook 的新命令行实用工具

前几天我与团队的另外一位项目经理交谈时他提到,他希望能够作为补救任务的一部分在 Operations Manager 中启动 Runbook,并且提到如果有一种命令行实用工具让他可以通过一个简单的命令快速执行此操作,那就太好了。我还一直在思考是不是可以使用 Windows 任务计划程序定期启动 Runbook,以避免在 Orchestrator 中计划活动的复杂性。当然,该主题在讨论列表中不时重复出现,尽管我们讨论了使用 Web 服务或 Web 服务的 PowerShell,但这些过程仍然没有那么简单。

所以今天早上我决定坐下来整理出一个简单的命令行实用工具,以便使用 Web 服务启动新的 Runbook 作业,但该实用工具要能够通过脚本很容易地启用或能够通过其他工具使用的命令行启用。几小时后,在处理我通常收到的所有电子邮件和会议请求的空隙中,我完成了一个原型。又经过几个小时的调整、改进并细查更多电子邮件和会议请求后,我终于有了可以实际发布给每个人作为示例尝试使用的东西。

我亲切地将这个工具称为 SCO Job Runner(我知道…为什么要花数百万美元进行市场调研呢?),它主要有两项功能。其一,它运行新的 Orchestrator Runbook 作业(你们已经猜到了,对吗?)。其二,它允许您获取 Runbook 的参数,这些参数的格式已设置为实用工具预期在命令行上收到它们的格式。

等一等!还有更多功能!只要您能够访问 Orchestrator Web 服务,就可以从任何位置运行该实用工具(您可以指定 Web 服务器和端口)。如果愿意,您可以使用备用凭据。您甚至可以告诉它要在哪个 Runbook 服务器上运行作业!没错!太神奇了!

如果不带任何参数运行该实用工具,您会得到以下用法:

SCOJobRunner - a command line tool to invoke runbooks for Orchestrator 2012.

SYNTAX
ScoJobRunner -ID:<runbookID> [-Parameters:<job parameters>]
[-Webserver:<server>] [-Port:<port number>] [-RunbookServer:<server>]
[[-Username:<username>] [-Domain:<domain>] [-Password:<password>]]
[-Verbose]

ScoJobRunner -ID:<runbookID> -GetParameters [-Verbose]

PARAMETERS

  -ID <string>
     The runbook ID to be invoked in the format of a GUID
     (i.e. "2d2fd2b4-339a-47ad-9914-a217d9fd47a6").

  -Parameters <string>
     A list of name-value pairs of the parameters needed by the runbook.
     The format of these parameters is: "Name=Value;Name=Value"
     Enclose in quotes to correctly handle spaces.
     Example:  -Parameters "Path='Path 1';Other Text='sample data here'"

  -GetParameters
     When this parameter is added, the utility returns a list of the runbook
     parameters formatted in a way you can use them on the command line.
     Example return value: "Path='Path 1';Other Text='sample data here'"

  -Webserver <string>
     The name of the Orchestrator server where the web service is installed.
     If not provided, defaults to the current computer.

  -Port <int>
     The port number used by the web service. If not provided, defaults to 81.

  -RunbookServer <string>
     The Runbook Server where the job should be run.
     If not provided, defaults to the configured primary Runbook Server.

  -Username <string> -Domain <string> -Password <string>
     If provided, allows the use of alternate credentials for invoking the
     runbook. All three parameters must be specified if used.
     If not provided, the current user credentials are used.

  -Verbose
     If this parameter is included, provides additional console output during
     the processing of the job creation process.

该实用工具使用起来非常简单。首先,我需要获取要运行的 Runbook 的参数,以确保正确填充它们。为此,我只需要输入以下命令:

SCOJobRunner -ID:"2d2fd2b4-339a-47ad-9914-a217d9fd47a6" -GetParameters

然后,为了运行作业,我获取返回的字符串:

"Path='value';Other Text='value'"

…并将它用在一个新命令行中,以使用实际参数值修改“value”部分。例如:

SCOJobRunner -ID:"2d2fd2b4-339a-47ad-9914-a217d9fd47a6" –Parameters:"Path='Path 1';Other Text='some other text here'"

注意:请确保使用单引号将包含空格的参数值括起,以便系统可将这些参数值视为一个值。

就是这样!这就是从命令行运行作业需要执行的全部操作。当然,如果我想从台式机运行该命令,但 Web 服务位于另一台计算机上,我可以将该命令的格式重新设置为如下所示:

SCOJobRunner -ID:"2d2fd2b4-339a-47ad-9914-a217d9fd47a6" -WebServer:"scoserver" -User:administrator -Domain:mydomain -Password:myPassword -Parameters:"Path='Path 1';Other Text='some other text here'"

 

现在,只要我知道 Runbook ID 和安装 Web 服务的计算机,我就可以从任何位置启动作业。没错,我知道使用 Runbook ID 来指定要运行的作业绝非最讨人喜欢的方式。但是,它确实提供一种独特的方法来确定哪个 Runbook 将要运行。不过,您的系统中会有多少“新建 Runbook”Runbook 呢?

将来我会再写一篇博客来介绍此实用工具的不同使用方法,包括任务计划程序、Operations Manager、Configuration Manager 等等。在此之前,请下载和试用该实用工具,并告诉我您的想法!

在此处下载包含实用工具的 zip 文件:SCO Job Runner - 命令行实用工具

在此处下载实用工具的源代码:https://orchestrator.codeplex.com/SourceControl/list/changesets