Topic
This article explains how to use environment variables when running scripts in NinjaOne.
Environment
NinjaOne Endpoint Management (automation and scripting)
Description
When a script that includes variables is executed, the NinjaOne agent adds them as environment variables only for the lifetime of the script's execution. If the system already has an existing environment variable being sent from the script, the script fails and sends an activity log clarifying what script failed and why.
Scripts also send an activity log entry for changes made to a script variable to the Activities tab in the System and the Device dashboards. This information can help users identify and plan for debugging or troubleshooting needs.
Select a category to learn more:
- Important Notes
- Create Script Variables
- Edit or Delete Created Variables
- Add Variables to a Script
- Additional Resources
Important Notes
- You can view, edit, and delete added script variables in the script editor's Script variables pane.
- You can reorder the list of variables by importance or priority.
- You can add a maximum of 20 variables to a single script.
- NinjaOne supports Unicode characters (non-Latin scripts, symbols, Kanji, emojis, and others).
- You cannot use the following special characters:
&|;$><`!.
Environment Variables
We also expose the following environment variables you can use for all types of scripts (Windows, macOS, 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 serverCreate Script Variables
You can add new script variables from the Script Variables field in the script editor. Refer to NinjaOne Endpoint Management: Getting Started with Automation to learn more.
- Click Add and select an option from the drop-down menu. For a description of each variable, refer to NinjaOne Endpoint Management: Automation Script Variable Types.
- The Add variable window will open and display configuration options that are relevant to the type of variable you selected. Refer to the table below for an explanation of each configuration field and the variable types to which it applies.
| Field | Description | Relevant Variable Types |
|---|---|---|
| Make variable mandatory | Activate the toggle to make the variable a requirement when the script runs. If activated, the form generated by the script will not run if this value is not present. | All except Checkbox |
| Name | Give your variable a descriptive name. NinjaOne will automatically c | All |
| Calculated name | NinjaOne will automatically populate a variable name in this field. | All |
| Description | This optional field sets a description of the variable. When running a script, NinjaOne displays the description as an informational tooltip icon (i) over the variable, which provides more information or helpful tips. | All |
| Set default value | This optional value uses pre-defined content when the script is run. The format of this field will change based on the variable type selected. | All |
| Option value | This mandatory value allows users to select options from a list. Each value entered provides a separate option. | Dropdown |