Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 9

Powershell script in templates

Hi @everybody,

Asked about this a while ago but didn't get it to work since then:

We are using templates for creating new users and we want to execute a simple powershell script. 

Fresh installation: Server 2019 and ARM -> New database, new config. 

According to the manual, scripts must be in C:\ProgramData\\8MAN\scripts\analyze  

This folder is being shared. The script is called nh.ps1. It works when executing in powershell on the ARM-server with of course fixed parameters for samaccountname etc...


Inside the template:


      // Define scripting options. 
    "ScriptOptions" : {
        /* (optional) Hide the scripting area. Stronger than IsHiddenFromRequester.
        If a script is defined it will be executed even if the area is hidden. */ 
        // (optional) Hide the scripting area for requesters in web interface. Weaker than IsHidden.
        // (optional) Define the checkbox preset. Default is false (if not set).
        // Set a display name.
        "DisplayName""Set Alias",
        // Path to the script file. Use UNC format and mention escaping.
        // (optional) Define the parameters that will be passed to the script.
        "CommandLineParameters""{samaccountname} {givenname} {sn}"


So, this one hands over the parameters to the  powershell script which supposed to change the mailnickname.

Set-ADUser {samaccountname} -Replace @{MailNickName = <subst>(<tolowerCase>(<firstLetter>({givenname})).<tolowerCase>({sn}))

On executing the template, there is no error but also no immediate feedback via email whether the script execution suceeded.

After 2 hours, ARM reports the error.

[date time] __ [000] powershell.exe -inputformat none -File "\\server\analyze\nh.ps1" xxyy xx yy

(xxyy = samaccountname | givenname=xx | sn=yy ) 


What exactly does the error mean?

Not sure about how to read any logs. Any ideas what could be wrong?




0 Kudos
2 Replies
Level 10

Hi swg,

as mentioned in the other thread ( the powershell code you posted will not work.

You can find an example for how to declare and use parameter values in the scripts in this post: (below the screenshots).

Have you tried testing your script as I described in the other post?


The "Error" you see is basically just the information on how ARM called your script. Where exactly do you see the message?

Usually if a script execution fails you will see an event in the logbook and that event will have a link to the transcript of the execution.

If you can see the powershell process running (just look at task manager) and its not finishing (sound like it might have run into a timeout if the execution time is always around 2hrs) the problem is most likely that the script is waiting for user input. This can happen if you forget a parameter or pass an empty value to it. Testing the script as described in my other post will enable you to catch these issues.

When the script is executed in ARM it is executed in a non-interactive session so user input is not possible and therefore the script will stall and not produce output.

0 Kudos

Ah thanks...

Went through erverything again. Took a long time but now I understand the  $args....

Changed also path to c:\\scripts\\ 

Another error was the duplicate token 1346 which I forgot about after reinstalling...

Scripts are working now

0 Kudos