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 (1.3k points)

1 Answer

0 votes
by (177k 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, is there possibility to search some custom string across all powershell script files used in Adaxes? I.e. Custom commands, Scheduled tasks etc I need to find out where is used some PowerShell command to be able to replace it for another one..

asked Apr 27 by KIT (2.6k points)
0 votes
0 answers

Image the users CSV fil provided hy HR system suddenly has a slight change to all 20000 users, is there a way to have Adaxes alert or halt before a certain number of changes set in a threshold are done ? Thanks

asked Apr 14 by spinnetho (250 points)
0 votes
1 answer

Hi, is it possible to increase mouseover popup limit from 5 to 6? We need to add one more attribute.

asked Apr 9 by KIT (2.6k points)
0 votes
1 answer

Hi, I followed this example: https://www.adaxes.com/sdk/IAdmTop6.html, but because the Custom Command is disabled, I get the following error message: System.Management.Automation ... if I enable the Custom Command. I am using Adaxes 2018.2 Best Regards Martin

asked Feb 19 by Martin (280 points)
0 votes
1 answer

I'd like to be able to either send an email report or export a CSV of all of the business rules carried out when a user is disabled. This would be ... Management Activity section but this includes things that weren't part of the disable operation. Thanks

asked Feb 19 by bavery (250 points)
2,181 questions
1,946 answers
5,391 comments
5,200 users