0 votes

Dear support, I'm trying to automate network share creations via custom commands. They idea is to create share and groups with command A and schedule execution of Command B (assigning permissions) after AD sync to other site (in 3h).

I've succedded so far to create a scheduled task, with a custom command action and domain scope, but I'm strugling how to schedule Command B with necessary arguments (server and folder names). Can you please advise? Here's my code so far

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

$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"

$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the 'File server tasks' container

$scheduledTasksPath = $admService.Backend.GetConfigurationContainerPath("ScheduledTasks")

$scheduledTasksPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $scheduledTasksPath

$myContainerPath = $scheduledTasksPathObj.CreateChildPath("CN=File server tasks")

$myContainer = $admService.OpenObject($myContainerPath,$NULL, $NULL, 0)

# Create a Scheduled Task

$task = $myContainer.Create("adm-ScheduledTask", "CN=File server tasks")

$task.ObjectType = "Domain"

$task.Description = "Assign NTFS permissions and share %param-folder%"

$task.Disabled = $False

$task.ExecutionMoment = "ADM_BUSINESSRULEEXECMOMENT_BEFORE"

$task.OperationType = "none"

$recurrencePattern = $task.GetRecurrencePattern()

$recurrencePattern.RecurrenceType = "ADM_RECURRENCEPATTERNTYPE_ONCE"

$recurrencePattern.PatternStartDateTime = (Get-Date).AddHours(3)

$task.SetRecurrencePattern($recurrencePattern)

$task.SetInfo()

# Define actions and conditions for the task

$commandID = "{e944e4df-6081-4b9d-8640-52eede7d3615}"

$actionsAndConditions = $task.ConditionedActions.Create()

$actionsAndConditions.ConditionsLogicalOperation = "ADM_LOGICALOPERATION_AND"

$actionsAndConditions.SetInfo()

$action = $actionsAndConditions.Actions.CreateEx("adm-CustomCommandAction")

$action.ExecutionOptions = "ADM_ACTIONEXECUTIONOPTIONS_SYNC"

$removeAction = $action.GetAction()

$removeAction.CustomCommandId = $commandID

$action.SetAction($removeAction)

$action.SetInfo()

$actionsAndConditions.Actions.Add($action)

$task.ConditionedActions.Add($actionsAndConditions)

# Define the scope for the task

$scopeItem = $task.ActivityScopeItems.Create()

$scopeItem.BaseObject = $Context.TargetObject

$scopeItem.Type = "ADM_SCOPEBASEOBJECTTYPE_CONTAINER"

$scopeItem.Inheritance = "ADS_SCOPE_BASE"

$scopeItem.Exclude = $False

$scopeItem.SetInfo()

$task.ActivityScopeItems.Add($scopeItem)
by (850 points)

1 Answer

+1 vote
by (226k points)
selected by
Best answer

Hello Dmytro,

You will need to bind to the Custom Command, create arguments for the command execution, specify parameter values that will be used to execute the command in the Scheduled Task and then pass the arguments to the Arguments property of the action. Here is the code that will do the trick:

# Define actions and conditions for the task

$commandID = "{a7264a61-b77d-4386-a138-ec2557c5b3ba}" # Command ID
$commandDN = "CN=MyCommand,CN=Custom Commands,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # Command DN

# Create action set
$actionsAndConditions = $task.ConditionedActions.Create()
$actionsAndConditions.ConditionsLogicalOperation = "ADM_LOGICALOPERATION_AND"
$actionsAndConditions.SetInfo()

# Create execute Custom Command action
$action = $actionsAndConditions.Actions.CreateEx("adm-CustomCommandAction")
$action.ExecutionOptions = "ADM_ACTIONEXECUTIONOPTIONS_SYNC"

# Get action
$removeAction = $action.GetAction()

# Bind to Custom Command
$customCommand = $Context.BindToObjectByDN($commandDN)

# Specify command arguments
$arguments = $customCommand.CreateArguments()
$arguments.SetParameterValue("MyParameter", "MyValue") # Parameter value

# Configure the action
$removeAction.CustomCommandId = $commandID
$removeAction.Arguments = $arguments

# Save action
$action.SetAction($removeAction)
$action.SetInfo()

In the script, the $commandDN variable specifies the distinguished name (DN) of the Custom Command. For information on how to get the DN of a directory object, see http://adaxes.com/sdk/?HowDoI.GetDnOfObject.html.

For details, have a look at the following SDK article: http://adaxes.com/sdk/?IAdmCustomCommandAction2.html.

Related questions

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 (190 points)
0 votes
1 answer

On Approval Requests, in the web console, Initiator shows "N/A" instead of the custom command scheduled task. The admin console shows the custom command scheduled task though. Any way to fix that?

asked Jan 21, 2021 by mark.it.admin (2.0k points)
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

We have several scripts that use the following action: $commandID = "{b4b66610-be71-403a-a6b7-8bcf51d200ef}" $user.executecustomCommand($commandID) is there syntax that allows ... is there another way to pass parameters to a custom command through scripting?

asked Jul 11, 2019 by ggallaway (300 points)
0 votes
1 answer

Is there a way to pass parameters to a script run through Adaxes? I tried placing it in the Script text box under Action Parameters as shown in the attached screenshot but it seems to completely ignore the parameter.

asked Jan 5, 2017 by rbeu (100 points)
2,779 questions
2,512 answers
6,574 comments
25,746 users