Blog

SCOM: Input and Pass user input parameters to Console Task

 

This is a small thing I figured out to request user input and pass it as a parameter to a console task by using PowerShell.

Issue:

The client wanted to be able to create tickets from an alert in the console if they were missed by an operator or notification script. The notifications pass the different parameters to a PowerShell script that generates the ticket. So far so good. But they wanted to call the notification from a Alert Console task. There are different parameters that need to be customized per alert to generate the correct ticket. One option was to create an Alert Console task for ALL the different classifications of alerts which would be a nightmare from manageability perspective + clutter the console.

Solution:

I came up with a small PowerShell script which will ask the user for input and use that input to generate the ticket with the correct info. The user still needs to know what to fill in but still it’s better than creating all the different Alert Console tasks.

This script is reusable in all your scripts you need to make interactive so you can prompt users for input during a console task.

Example:

In this example I’ve created a small Alert Console Task to connect to a Remote server via Remote desktop connection which can be different than the server which is generating the alert you’ve selected.

The PowerShell script I used in this example can be downloaded here

1. Creating the console task:

First things first. We need to create the console task.

Navigate to the Authoring pane > Management pack objects > tasks > create new task.

In the selection window select a Console Task > Alert Command line (This is necessary if we want to pass parameters from the alert to the script we would like to run)

SNAG-0007

Name your task.

Note: This will be the actual name which will appear in your console so keep it short and simple but clear enough so someone will know what the task will do.

SNAG-0009

Note: I’ve created a separate management pack for all my Console Tasks

Specify the command line options:

  • Application: %windir%\system32\windowspowershell\v1.0\Powershell.exe
  • Parameters: C:\scripts\consoletask\remotedesktop.ps1 $ID$ “$Managed Object Name$”
  • Working Directory: c:\scripts\consoletask\

Note: The script must be copied to the local computer where the console is installed. In this case: c:\scripts\consoletask\

Hints:

  • If you want to check what alert parameters you can pass to your script click the arrow behind the parameters field
  • Keep the “Display output when this task is run ticked as this is a great tool to check whether there are issues with your script during execution. If you are convinced after testing that the task is working you can change it to hidden.

SNAG-0013

2. Check the Console Task

When saved, the Task will appear between the Alert Tasks in the task pane when you select an alert.

SNAG-0012

When you click the task the Console Task Output window will pop up together with a window asking the user to put in a servername. If the user clicks cancel the task is terminated.

SNAG-0041

Success! The remote connection is started with the server we have put in!

SNAG-0042

3. Disable the Output window

Now that we have verified everything is working we can disable the task console window so only the prompt for input is shown.

Open the task properties and deselect the box “Display output when this task is run”

SNAG-0010

SNAG-0040

4. PowerShell Script

The PowerShell script I used in this example can be downloaded here

 

The section which is responsible for the input is here so if you have existing scripts this is what you are looking for to make them interactive:

#Get the server to connect to
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null
$server =  [Microsoft.VisualBasic.Interaction]::InputBox(“Enter a Servername”, “Servername”, “”)

Enough talk, let’s build
Something together.