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 (260 points)

1 Answer

0 votes
by (272k 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 (340 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

I'm trying to schedule a report to look in a few specific OUs. Currently "Look in" location only allows for single instance or multiple drop downs. How do I schedule multiple OU locations without creating multiple reports?

asked Jul 2, 2020 by Al (20 points)
0 votes
1 answer

I'd like to limit users from being able to login to the Web interface. In other words, if a user opens multiple browsers or tabs, can I prevent them from being able to login to each tab/browser and starting multiple sessions? Thanks!

asked Apr 10 by cewilson (140 points)
3,346 questions
3,047 answers
7,772 comments
544,971 users