0 votes

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

by (960 points)

1 Answer

0 votes
by (287k 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, 2020 by barberk (60 points)
0 votes
1 answer

Is there a way to have a Scheduled Task with 4 different condition? I want to create a scheduled task start every Monday and the condition see: The next Saturday of the week ... of the week is the fifth of the month then no action Thanks in advance, Simone

asked Jan 18, 2022 by Simone.Vailati (430 points)
0 votes
1 answer

The script create two reports of inactive workstation operating systems. The report is too detailed to run from one of the adaxes reports. Basically how can I set the script up to ... sure How I did this but I can't find it now (probably something simple).

asked Nov 30, 2022 by mightycabal (1.0k 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, 2020 by hgletifer (1.3k 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 (290 points)
3,526 questions
3,217 answers
8,197 comments
547,625 users