根据事件日志触发Powershell [英] Trigger powershell based on event log

查看:172
本文介绍了根据事件日志触发Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用PowerShell编写的命令行参数脚本,该脚本接受任务计划程序中的服务器名称.但是,我的要求是在重新启动SQL Server时执行脚本,因此我将PowerShell脚本附加到事件17069.但是,我无法动态传递事件源(在这种情况下为服务器名称).

I have a command line argument script written in PowerShell which accepts server name from the task scheduler. However my requirement is to execute the script when the SQL server is restarted, hence I have attached the PowerShell script to the event 17069. But I am unable to dynamically pass the event source which would be the server name in this case.

下面是任务计划程序作业的参数部分

Below is argument section of the task scheduler job

-Command "& 'D:\SQLJobs\PS\readErrorLogFile.ps1' '$(Source)'"

$(Source)在启动powerShell时未从事件视图中获取事件源.您能告诉我如何获取事件源吗?

$(Source) does not pick up the event source from event view while firing the powerShell. Can you please let me know how to pick up the event source.

正如评论中所建议的,我已使用下面的XML分支更新了我的任务计划程序工作

As suggested in the comments I have updated my task scheduler job with below XML branch

<ValueQueries>
<Value name="server">Source</Value>
</ValueQueries>

上述脚本已插入<EventTrigger>分支中.

The Above script has been inserted in <EventTrigger> Branch.

下面是PowerShell CMD行输入脚本.

Below is PowerShell CMD line input script.

 param (
    [string]$server
 )

请让我知道在任务计划程序作业的参数部分中需要提及的内容,因为$(server)在脚本中显示为空.

Kindly let me know what needs to be mentioned in the argument section of the task scheduler job as $(server) displays null in the script.

推荐答案

我认为您要查找的内容在此处描述:

I think what you're looking for is described here:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆