- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 08:29 AM
We are attempting to create a simple custom PowerShell activity that leverages the "Set-ADUser" command. I am able to run the passed script on the MID Server with the same user we are using in the activity, however when running the MID Server Script file from the activity, we are met with the error:
"errorMessages": "The term 'Set-ADUser -Identity tsink2 -AccountExpirationDate 2019-02-01.19:00:00 -replace @{\"title\"=\"Test\"}' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.\nHRESULT: [-2146233087]\n\nStack Trace: at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)\nat System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)\nat System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\nat System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\n",
The Mid Server Script we are using is below:
import-module "$executingScriptDirectory\AD\ActiveDirectory"
if (test-path env:\SNC_Script) {
$script=$env:SNC_Script;
};
$script -useCred $useCred -credential $cred
the variable $script is passing the following script which is built earlier in the WF:
Set-ADUser -Identity tsink2 -AccountExpirationDate 2019-02-01.19:00:00 -replace @{\"title\"=\"Test\"}
According to the article below, we may need to add pre-processing, however I am unable to find any documentation or examples that have worked.
https://docs.servicenow.com/bundle/london-servicenow-platform/page/administer/orchestration-activity-designer/task/t_CreateAPowershellActivity.html
Thanks,
Side-note: We are unable to use the OOB Update AD Object Activity as this will be used on a much larger scale that the OOB activity is unable to handle.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 01:42 PM
Yea I am not sure an input can accept an input. Have you tried putting a name in that script input first just to see if the script will even run as an input before using variables in it (assuming tsink2 is a variable)?
Also, have you attempted putting the script on the midserver and calling it from there? You can pass variables to it that way.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 01:04 PM
Update:
If I hard-code the script into the custom PowerShell Command, it works:
If I try to pass the script through as an input:
I am then met with this error:
If I hard-code the script into the custom PowerShell Command(just as the first image), and I also leave "Set-ADUser -Identity tsink2 -AccountExpirationDate 2019-02-01 -credential $cred" in the activity Input "Script," I am getting the same error.
It is almost as if the input is trying to run the command before it hits the custom PowerShell command portion of the activity. I tried placing the script in the input in single and double quotes and I am getting the same issue.
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 01:26 PM
I know you said you can't use the OOB Update AD Object, but you can set Account Expirations with it. We use it to activate vendor accounts in our environment (people who aren't here all the time):
But with relation to your current issue...I ran into a similiar situation the other day and I had to set my script to a variable then dot walk to the name field I wanted.
This is the error I was getting:
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 01:38 PM
Thank you for the quick response,
The reason we cannot use the OOB is due to the scale of this work. Currently we are only testing with the expiration date, however we need to update around 20 attributes for the AD user each time the WF is run and the OOB cuts us off if the attributes being passed exceeds a certain character length.
Additionally, your dot walk would work if we could get the script to pass to a variable. It seems that when the input sees the script in the activityInput.Script, it tries to run the script and errors. It doesn't write anything to the command, nor starts the command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 01:42 PM
Yea I am not sure an input can accept an input. Have you tried putting a name in that script input first just to see if the script will even run as an input before using variables in it (assuming tsink2 is a variable)?
Also, have you attempted putting the script on the midserver and calling it from there? You can pass variables to it that way.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2019 01:57 PM
You are fantastic!
I tried placing the word "Test" into the activityInput.Script and it errored out the same, saying "Test" was not the name of a cmdlt... etc.
I then changed the name of the input from "Script" to "PSCommand" and it now works like a dream. I am unsure if the word "Script" is a reserved work for the inputs, but that corrected it.
Thanks!