# ======================================================== # # Script Information # # Title: # Author: XYLOS\RivD # Originally created: 28/07/2014 - 18:59 # Original path: G:\Altiris\Tests\ASDK75_TaskScheduler.ps1 # Description: # # ======================================================== #region Customizable configuration #hostname of altiris server $global:altirisserver = "vm-alt-ns01" #Use https = 1; use http = 0 $global:https = 0 #use single signon = 1; use username and password = 0 $global:altirissso = 1 #credentials to use when not using single signon $global:altirisdomain = "ALTIRIS" $global:altirisuser = "Administrator" $global:altirispass = "Altiris01" #sample values #name of a single computer $computername = "COMPUTER01" #name of a task to execute $taskname = "Run Script - Hello World" #endregion $global:nsItem = New-Object -comObject Altiris.ASDK.NS.ItemManagement $global:nsColl = New-Object -comObject Altiris.ASDK.NS.CollectionManagement $global:nsSwPm = New-Object -comobject Altiris.ASDK.SMF.SoftwarePackageManagement $global:nsTaskMgmt = New-Object -comObject Altiris.ASDK.Task.TaskManagement $global:nsItem.targetserver = $altirisserver $global:nsColl.targetserver = $altirisserver $global:nsSwPm.targetserver = $altirisserver $global:nsTaskMgmt.targetserver = $altirisserver if($global:https -eq 1){ $global:nsItem.Protocol = "https" $global:nsColl.Protocol = "https" $global:nsSwPm.Protocol = "https" $global:nsTaskMgmt.Protocol = "https" } if ($global:altirissso -ne 1) { Write-Host "Performing authentication with user account" $global:nsItem.Username = $altirisdomain + "`\" + $altirisuser $global:nsItem.Password = $altirispass $global:nsColl.Username = $altirisdomain + "`\" + $altirisuser $global:nsColl.Password = $altirispass $global:nsSwPm.Username = $altirisdomain + "`\" + $altirisuser $global:nsSwPm.Password = $altirispass $global:nsTaskMgmt.Username = $altirisdomain + "`\" + $altirisuser $global:nsTaskMgmt.Password = $altirispass } $global:nsItem.authenticate() $global:nsColl.authenticate() $global:nsSwPm.authenticate() $global:nsTaskMgmt.authenticate() #Retrieve the GUIDS of Computer and Task $computerguid = ($nsItem.GetItemsByNameAndType($computername,"Altiris.Resource.StandardResources.ComputerResource"))[0] #Tasks can have different types, so not using GetItemsByNameAndType $taskguid = ($nsItem.GetItemsByName($taskname))[0].guid #Build input XML containing one or more GUIDS of computer resources. #Multiple GUIDS should be separated with a comma eg. 81043356-d7a6-44af-a673-20a467fdee14,ad2de238-66c7-4149-aea5-7d03af3ea5a9 $inputParam = "@AssignedResources" $inputParam = "$inputParam$computerguid" $inputParam = "$inputParam@CompRequirements2 minutes60 minutes100 %" #execute the task $taskexecutionguid = $nsTaskMgmt.ExecuteTask($taskguid,"PowerShell Execute $taskname",$inputParam)