Powershell rule executed locally on MS

Hi all, is there a possibility to execute a powershell rule locally on the MS ? I have seen something in a post by Kevin Holman, but it was not exactly targeted to PowerShell.


Have you heard of the PowerShell Authoring MP?


Create the rule using this MP, target the Windows Computer class, ensure it’s disabled by default. Enable it only for your management servers.

1 Like

Hi Dimitri, hope all is well.

This is possible, we do this for collecting shutdown events and to put them into maintenance mode.

There are two parts that are important here in our example.

  1. Tell the rule in a write action that it should be executed on a management server. In this example, look for the Target="". CollectionManagementServer tells the script to execute on any Management Server in your environment. <WriteAction ID="PS" TypeID="Digital.Operations.Autonomous.Maintenance.Mode.Start.Computer.Maintenance.WA" Target="SC!Microsoft.SystemCenter.CollectionManagementServer"> <TimeoutSeconds>60</TimeoutSeconds> <MaintenanceModeInMinutes>15</MaintenanceModeInMinutes> <ComputerInstance>$Data/LoggingComputer$</ComputerInstance> </WriteAction>
  2. The TypeID of the Write action (Digital.Operations.Autonomous.Maintenance.Mode.Start.Computer.Maintenance.WA) is a custom module that executes a PowerShell script with the parameters defined above. Part of the custom module looks like this: <WriteAction ID="PS" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction"> <ScriptName>Start.Computer.Maintenance.ps1</ScriptName> <ScriptBody>$IncludeFileContent/Scripts/Start.Computer.Maintenance.ps1$</ScriptBody> <Parameters> <Parameter> <Name>MaintenanceModeInMinutes</Name> <Value>$Config/MaintenanceModeInMinutes$</Value> </Parameter> <Parameter> <Name>ComputerInstance</Name> <Value>$Config/ComputerInstance$</Value> </Parameter> </Parameters> <TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
Please reach out if you need further assistance. You know where to find me.

// Jonas

OpsLogix / Approved

Thanks Jelly, of course I am using that MP, but I did not think about enabling it just for MS ?

I will try and let you know

Great to hear! It’s saved me a few times now :wink:

Seems not working. My problem is that I have to read an entry in eventlog on any monitored server and execute an action on the MS. If the rule is disabled it will never work.
Here https://kevinholman.com/2018/11/08/monitor-an-agent-but-run-response-on-a-management-server/ there was something but I cannot find a way to match this suggestion to my needs.

Ah I see, my suggestion will not suffice! Are you able to provide the script you’re using in your question?

Web-Applications-v1.1.zip (1.82 KB)

Web-Applications1.zip (1.81 KB)

Hi Jonas, it’s a long time indeed :slight_smile:
Thanks for your suggestion. I will try to adapt this to my solution because I am not working with XML directly, but I create the rule in scom console using PowerShell MP. So if I understood correctly I should edit the MP once created to do the requested changes at code level. Did I understand correctly ?

The Event Collection rule can be created without the PowerShell MP. You just need to add a custom Write Action (WA) on the newly created rule and make sure it has the Management Servers on target. Not sure if the PowerShell MP can be used for creating the custom write action though.

So I have created a brand new MP based on Kevin Holman’s blog here… https://kevinholman.com/2018/11/08/monitor-an-agent-but-run-response-on-a-management-server/
I cannot paste the code here because the tags modify the page (the mysteries of XML :stuck_out_tongue: )
And it does NOTHING…
It is imported correctly, And theorically it should work fine (I simply created an empty MP and added the code from Kevin).

I have no options right now.