0 votes

Hi, I need to start Adaxes scheduled task from Powershell console running on another host. How can I do that?

by (3.1k points)

1 Answer

0 votes
by (189k points)

Hello,

You can use the below script in Windows PowerShell. In the script:

  • $adaxesService - Specifies the DNS host name of the desired Adaxes service.
  • $taskName - Specifies the name of the Scheduled Task to be run.

When prompted for credentials during script execution, specify the credentials of the Adaxes service account (specified during Adaxes installation) or credentials of another user that has permissions to manually execute Scheduled Tasks.

For the script to work, you need to install Adaxes Powershell Module for Active Directory on the computer where the script will be executed.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$adaxesService = "adaxesserver.company.com" # TODO: modify me
$taskName = "My Task" # TODO: modify me

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly($adaxesService)

# Prompt for credentials
$credential = Get-Credential

# Bind to the Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath("ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath("CN=$taskName")
$myScheduledTask = $admService.OpenObject($myScheduledTaskAdsPath, $credential.UserName, $credential.GetNetworkCredential().Password, 0)

# Run the Scheduled Task
$myScheduledTask.RunNow()
0

Can I omit entering credentials? I will use PSRemoting, so in fact run the commands locally.

PS: I absolutely love your support, quick precise answers ;)

0

Hello,

Can I omit entering credentials?

Yes, it is possible. Here is the updated script. It will use the credentials of the logged on account.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$adaxesService = "adaxesserver.company.com" # TODO: modify me
$taskName = "My Task" # TODO: modify me

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly($adaxesService)

# Bind to the Scheduled Task
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath("ScheduledTasks")
$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $scheduledTasksPath
$myScheduledTaskAdsPath = $scheduledTasksPathObj.CreateChildPath("CN=$taskName")
$myScheduledTask = $admService.OpenObject($myScheduledTaskAdsPath, $NULL, $NULL, 0)

# Run the Scheduled Task
$myScheduledTask.RunNow()

PS: I absolutely love your support, quick precise answers ;)

Thank you for your good words, it is much appreciated!

0

It failed with error, that object xyz does not exist. This is because scheduled task is not in root of 'Scheduled Tasks' container but in subcontainer, so its ADS path is Adaxes://ourserver:34809/CN=TASKNAME,CN=Servers,CN=Scheduled Tasks,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes

So how can run task that is not in root? Best possible way would be to search for that taskname under Scheduled Tasks container :)

0

Hello,

There is no need to perform a search. Use the below updated script. In the script, the $taskPath variable specifies the ADS Path of the Scheduled Task to be executed. To get the path:

  1. Launch Adaxes Administration Console.
  2. In the Console Tree, expand your service node.
  3. Navigate to Configuration\Scheduled Tasks.
  4. Right-click the Scheduled Task you need.
  5. In the context menu, open the submenu of the Copy item.
  6. Click Copy ADS Path. The Path of the selected Scheduled Task will be copied to the clipboard. image.png
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$adaxesService = "adaxesserver.company.com" # TODO: modify me
$taskPath = "Adaxes://adaxesserver.company.com:28102/CN=My Task,CN=My Container,CN=Scheduled Tasks,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly($adaxesService)

# Bind to the Scheduled Task
$myScheduledTask = $admService.OpenObject($taskPath, $NULL, $NULL, 0)

# Run the Scheduled Task
$myScheduledTask.RunNow()
0

Yeah I figured that I can put whole path in it, but I want to turn this code into a powershell function, so it would be nice just to enter taskName and don't force users to search for exact ADSpath :) But dont bother if this is too much :)

+1

Hello,

Sure, we updated the script accordingly, here it is:

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$adaxesService = "adaxesserver.company.com" # TODO: modify me
$taskName = "My Task" # TODO: modify me

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly($adaxesService)

# Search parameters
$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath("ScheduledTasks")
$searcher = $admService.OpenObject($scheduledTasksPath, $NULL, $NULL, 0)
$searcher.SearchFilter = "(&(objectClass=adm-ScheduledTask)(name=$taskName))"
$searcher.SizeLimit = 2

try
{
    # Execute search
    $searchResultIterator = $searcher.ExecuteSearch()
    $searchResults = $searchResultIterator.FetchAll()

    if ($searchResults.Length -eq 2)
    {
        Write-Warning "Found more than one Scheduled Task called $taskName"
        return
    }

    if ($searchResults.Length -eq 0)
    {
        Write-Warning "Scheduled Task called $taskName not found"
        return
    }

    # Bind to Scheduled Task
    $task = $admService.OpenObject($searchResults[0].AdsPath, $NULL, $NULL, 0)

    # Run the Scheduled Task
    $task.RunNow()
}
finally
{
    # Release resources
    if ($searchResultIterator){ $searchResultIterator.Dispose() }
}
0

Perfect as always. Thank you :)

And one last thing. How can I wait for the tasks end? I cannot find any property or method on that $task object that contains such information.. So is there possibility to check that task actual status?

0

Hello,

Yes, it is possible. For us to update the script for you, please, specify all the possible details in regards the running status. Live examples will be very helpful.

Related questions

0 votes
1 answer

I have an ADP Sync scheduled task that modifies and creates users from a csv file. I also have reports that show new users created and management history for user ... ADP Sync scheduled task so that they only run after the ADP Sync task is complete?

asked Jan 7 by barberk (290 points)
0 votes
1 answer

I have a feild called Decommissioned Date and I can not figure out how to run a scheduled task the day after that date. So If an account got decommissioned today I want the task to run tomorrow.

asked Jan 9 by hgletifer (6.8k points)
0 votes
1 answer

I have a scheduled task that runs a Powershell script against an AD group, "Group 1". I need to get all of the members of Group 1, and add them to Group 2. The ... identity in the error message start with 'user;'? What is the correct way to accomplish this?

asked Aug 27, 2019 by ngb (280 points)
0 votes
1 answer

Hello, I am trying to figure out how to create a scheduled task via PowerShell. I've been referencing the SDK, mostly pulling script examples straight out of it. After following the steps on ... ==================> # Save the Scheduled Task $task.SetInfo()

asked Feb 23, 2015 by DFassett (4k points)
0 votes
1 answer

Hello - I'm working on my companies off boarding process and need to run a Custom Command that turns off access to different systems and resources at the ... -9612-c7c982baa49f}" $user.ExecuteCustomCommand($commandID) # Save the Scheduled Task $task.SetInfo()

asked Jul 16, 2015 by jakesomething (1.1k points)
2,352 questions
2,107 answers
5,746 comments
135,367 users