Quantcast
Channel: Symantec Connect - Endpoint Management - Articles
Viewing all articles
Browse latest Browse all 861

Stopping A Job/Task (Remotely)

$
0
0

I've seen a number on questions raised on connect about whether or not the ASDK web services support the stopping of a job or task. Unfortunately the Task Management Service doesn't support this but the same functionality can be achieved by using the workaround outlined in this article.

The workaround is to have a server task on the notification server which has access to the Altiris assemblies and can stop a given task. The Task Management ASDK service then executes this server task and passes in the job/task instance GUID of the job/task to stop.

Create the Server Task PowerShell Script

1. Create a new Server Task on the Notification server.

2. Set the Script Type to PowerShell

3. Paste the following code content into the task's body.

##
## Load the relevant assemblies from the GAC
##
[reflection.assembly]::LoadWithPartialName("Altiris.TaskManagement")
[reflection.assembly]::LoadWithPartialName("Altiris.TaskManagement.Data")
[reflection.assembly]::LoadWithPartialName("Altiris.TaskManagement.Common")

##
## The Task Instance to stop - The service will pass this in
##
$instance = [Guid]("%!TaskInstance!%")

$TaskInstanceGuid = New-Object -TypeName Altiris.TaskManagement.Common.TaskInstanceGuid -ArgumentList $instance
$taskInstance = [Altiris.TaskManagement.Data.TaskExecutionInstance]::GetTaskInstance($TaskInstanceGuid)

$status = New-Object -TypeName Altiris.TaskManagement.UI.XmlCallback.StopServerTaskInstances+StopStatus

##
## Get the database context
##
$db = [Altiris.NS.ContextManagement.DatabaseContext]::GetContext()

##
## Stop the Job/Task
##
$status.Stopped = $taskInstance.Stop($db, [ref]$status.NonStopped)

4. Press Save Changes.

5. Right-click on the task in the treeview and selecting Properties.

6. Note the task's GUID as we will need this later on. We will use this GUID to tell the Task Management Service to execute this task.

Guid Properties2.JPG

Executing the Task

We now have a task on the NS server which is capable of stopping any job/task instance that is running. This task can now be called remotely using the Task Management Service's ExecuteTask Method.

http://<NSServer>/Altiris/ASDK.Task/TaskManagementService.asmx?op=ExecuteTask

Example of Calling the ExecuteTask Method

Below is an example of how you can call the execute task method using PowerShell.

  1. Update the $taskGuid variable to be the GUID of your PowerShell task on the notification server
  2. Updated the $service variable to reflect your notification server.
##
## TASK INSTANCE TO STOP
##
param(
    [parameter(Mandatory=$true)]
    [string]$taskInstance
)

##
## THE POWERSHELL TASK GUID - UPDATE TO REFLECT YOUR POWERSHELL TASK GUID
##
$taskGuid = "5e103b51-f5a4-4b84-9c83-81228b611242"

##
## SERVICE WSDL - UPDATE TO REFLECT YOUR NS
##
$service = "http://<NSServer>/Altiris/ASDK.Task/TaskManagementService.asmx?WSDL"

##
## PROMPT THE USER FOR CREDENTIALS
##
$cred | Out-Null
if($cred -eq $null)
{
    $cred = Get-Credential
}

##
## CREATE A PROXY
##
$proxy = New-WebServiceProxy -uri $service -namespace WebServiceProxy -Credential $cred


##
## BUILD OUR PARAMETER XML
##
$parameter = "<parameter>
        <name>TASKINSTANCE</name>
        <value>$taskInstance</value>
    </parameter>"

##
## CALL OUR POWERSHELL TASK PASSING OVER OUR TASK INSTANCE
##
$proxy.ExecuteTask($taskGuid, "Stop Task!", $parameter)

Now you can remotely stop running jobs and tasks using the ASDK services!

Christopher McEwen
Developer

Protirus


Viewing all articles
Browse latest Browse all 861

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>