0 votes

I'm running into the following error when I run the command:

You cannot call a method on a null-valued expression. Stack trace <ScriptBlock>, <Nofile>:Line 24

I'm using the following script:


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

# Bind to the Custom Command
$commandID = "{ID}"

# Specify arguments for command execution
$commandArguments = $command.CreateArguments()
$commandArguments.SetParameterValue("param-1", "Value 1")
$commandArguments.SetParameterValue("param-2", "Value 2")

# Specify User to run the command on
Import-Module Adaxes -Cmdlet Get-ADMUser
$user = Get-ADMUser -Identity %distinguishedName%

# Execute the Custom Command
$user.ExecuteCustomCommand($commandID, $commandArguments)
'''
by (220 points)

1 Answer

0 votes
by (213k points)

Hello Richard,

Sorry for the confusion, but it looks like you provided an incomplete script (the bind to Custom Command part is missing). Also, to execute a Custom Command on an object, you need to bind to it, not just obtain using the Get-AdmUser cmdlet. As we understand, the script is executed in a Custom Command, Business Rule or Scheduled Task where the user on which the Custom Command should be run is the target object. If that is correct, there is no need to use scripts, you can use the Execute a Custom Command action and use the Parameters option to specify parameter values: image.png

0

Hi,

I've anonymised some of the info as it's specific to our company, I've only shown part of the script here, some variables that need to be added as parameters in the custom command need to be acquired from an external source.

I'm specifically calling the ID of the custom command using

$commandID = "{ID}"

I understand I can do this without using Get-ADMUser but i'm struggling to make it work regardless, I only need this to run on a specific user, not every user in an OU like the example above

0

Hello,

In your script, you need to bind to the target user involving Adaxes functionality using the $Context.BindToObjectByDNEx method with the second parameter set to $True. Finally, the script will be like below. In the script, the $commandDN variable specifies the distinguished name (DN) of the Custom Command to be executed.

$commandDN = "CN=my command,CN=Custom Commands,CN=Configuration Objects,CN=Adaxes Configuration,CN=Adaxes" # TODO: modify me

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

# Specify arguments for command execution
$commandArguments = $command.CreateArguments()
$commandArguments.SetParameterValue("MyParameter1", "MyValue1")
$commandArguments.SetParameterValue("MyParameter2", "MyValue2")

# Bind to the target user
$user = $Context.BindToObjectByDNEx("%distinguishedName%", $True)

# Execute the Custom Command for the user
$user.ExecuteCustomCommand($command.CommandID, $commandArguments)

If you still have issue running the script, please, send us (support[at]adaxes.com) the full script you are using and a screenshot of the configuration object (e.g. Business Rule, Scheduled Task) that runs the script.

Related questions

0 votes
1 answer

Hi Everyone I want to create a custom command where I can select multiple users and then select a mailbox and give them full access to the mailbox. Is there a way to do it? Thank you for help

asked Nov 2, 2021 by Sandberg94 (170 points)
0 votes
1 answer

Hi Currently we have an Adaxes system set up for our Service Desk staff to log into and manage users / groups etc this is currently assigned by assigning the Service ... there be any limiting factors such as licencing requirements for this? Thanks in advance.

asked Dec 15, 2020 by R_C (70 points)
0 votes
1 answer

Here is what i have been trying with Set-ADUser -Identity $user -Clear "extensionAttribute5" Set-ADUser -Identity $user -Add @{extensionAttribute5 = "NoLicenseNeeded"}

asked Nov 29, 2021 by Markh (20 points)
0 votes
1 answer

How can I send more than just one report by email? I only have the option to schedule reports one by one in separate emails. Is it possible to send Overview reports that contain multiple reports in one?

asked Oct 1, 2021 by manomano (60 points)
0 votes
1 answer

Is it possible to send an email from Adaxes when certain AD objects are modified outside of Adaxes? With Business Rules it looks pretty easy to do that inside of Adaxes ... something changes on the object and the change was not initiated by Adaxes. Thank you.

asked Jul 23, 2021 by mikek (80 points)
2,634 questions
2,369 answers
6,291 comments
969,111 users