Already a NinjaOne customer? Log in to view more guides and the latest updates.

NinjaOne Endpoint Management: Automation Parameters

Topic

This article explains the purpose of parameters when installing or running scripts and automations in NinjaOne. 

Environment

NinjaOne Automation

Description

The terms "parameters" and "arguments" are often used interchangeably, but they are very slightly different. When you call a function, a script or an executable file, you use arguments. When you define the function, you define the parameters that will take the arguments from the call for the parameter values. Within the scope of building automation scripts for NinjaOne these terms can be used interchangeably, so NinjaOne uses the term "parameters" throughout. 

Parameters are not required by default in custom scripts. However, if your custom script is written to accept parameters, you have the option of specifying preset parameter strings in the script editor.

How Do I Know What Parameters to Use in NinjaOne’s Native Install/Run Application Scripts?

For .EXE files, parameters are application specific. There is no one set of parameters to use.

For .MSI files, please click here for a list of possible parameters.

Important Note: For NinjaOne's native "Install Application" script, all .MSI files are executed using the following parameters:
/quiet /qn /norestart /log {path to our script folder}ninjascript-output-{current-time}.txt 

NinjaOne only accepts String value parameters. 

How Do I Know What Parameters to Use in My Custom Scripts?

Each scripting language has its own unique method of consuming script parameters. Parameters should be formatted per the requirements of the language your custom script uses. Here are some resources regarding how parameters work in the different scripting languages that NinjaOne supports:

Important Notes:

  • The following special characters cannot be used in parameters: &|;$><`!
  • NinjaOne is unable to pass multiple values for Array Parameters. For example, when adding -param 1, 2 into our parameters text box, it only outputs "1" instead of "1" "2". 
  • NinjaOne is currently unable to pass Boolean values through our parameters.
  • NinjaOne only accepts String value parameters. 

We also expose the following environment variables that can be used for all types of scripts (Windows, Mac, and Linux):

NINJA_EXECUTING_PATH -Install location
NINJA_AGENT_VERSION_INSTALLED -Agent Version
NINJA_PATCHER_VERSION_INSTALLED -Patcher Version
NINJA_DATA_PATH -Agent data folder (scripts, policy, downloads, logs)
NINJA_AGENT_PASSWORD -Agent password for obtaining session key
NINJA_AGENT_MACHINE_ID -The machine ID used on the server
NINJA_AGENT_NODE_ID -The node ID used on the server.
NINJA_ORGANIZATION_NAME -The organization name used on the server.
NINJA_ORGANIZATION_ID -The organization ID used on the server.
NINJA_COMPANY_NAME -The company name used on the server.
NINJA_LOCATION_ID -The location ID used on the server.
NINJA_LOCATION_NAME -The name of the location used on the server
Important Note: If you change a variable and execute a script to retrieve the new value, reboot the target if it has not changed. Rebooting the target will update the variables.

What Do Preset Parameters Look Like in NinjaOne?

The following is an example of passing parameters to a Batch script that creates a new user on a device.

script

In the scenario above, we are using the following batch script to create a new user:

net user %1 %2

%1 and %2 are values that will consume parameters (in this case, a username and password for the new user).

We created three preset parameter strings:

  • Bob Password1
  • Linda NewPassword
  • Joe Passw0rd

When executing the script, we can either specify parameters on-the-fly or choose from our list of preset parameter strings.

run

The parameters are passed to the respective values in the order that they are entered. So, if we choose the Bob Password1 preset parameters, Bob is passed to the value %1 in the script, and Password1 is passed to the %2 value—which results in a new user with the username Bob and the password Password1.

Whenever you create a new script in NinjaOne's Script Library, a new file is created such as 'customscript1.bat'. So, the command looks something like this with parameters:

customscript1.bat <YOUR PARAMETERS HERE>

Other Use for Preset Parameters:

If you do not want to enter hard text parameters in your script, you can also call empty variables inside your script and insert their values inside the field for parameters right before running your script.

Here is an example with a script calling three variables and displaying them in the output of the script: 

param(
 [String]$variable1='',
 [String]$variable2='',
 [String]$variable3='')


Write-Host $variable1
Write-Host $variable2
Write-Host $variable3
When running this script, enter the values you want each variable to take in the order in which they were written in your script. Use a space to differentiate each variable. 
In this example, variable1 takes the value "5.1.1574", variable2 the value "5", variable3 the value "1": 

run

If you have values with spaces in them, you need to add quotes to differentiate them from the other variables.
For example, if I want to add Peter Smith as a $Username and Pa5sW0rd as his $Password, I need to type them as follows:
"Peter Smith" Pa5sW0rd
Important Note: NinjaOne does not currently provide support for custom scripting. However, the Script Share topic in our forums is a great resource for sharing and requesting custom scripts. 

Default Parameters

For both app automation installation and app automation run there's a checkbox to set a parameter as the default option (set first option as the default value) when one or more parameters have been added to the automation.
Once set, this parameter will automatically be chosen and applied when that automation is run from anywhere in the app.
When running automation, users can manually select a different parameter to override the default.
Only one parameter can be set as the default at a given time, and can only be the one at the top of the parameters list.
If no parameter is selected as default, that automation will by default run without one.
Changing default parameters will not affect anything about how this automation is already used throughout the platform (if it's in a scheduled task, it will not change the parameters of the automation in that scheduled task). A total of max 50 parameters total allowed and a maximum of 30K characters per parameter.

ParametersDefault.png

 

FAQ

Next Steps