PowerShell Scripts

Modified on Tue, 3 Feb at 11:53 AM

TABLE OF CONTENTS


Overview

The PowerShell Scripts Panel in ManagementStudio is a central repository for scripts used across various features, including Scheduled Tasks, System Events, UI Buttons, and ESM processes (such as Plan Evaluation or Plan Actions). Scripts can be stored as text—using a default API template—or as file paths for larger scripts. Text-based scripts benefit from automatic version history.

Accessing the Scripts Repository

Scripts available to a project are accessible at:

  • Administration → PS Scripts, Emails, Buttons

You can also access scripts aligned to specific modules via:

  • Administration → [Module] → PowerShell Scripts

Additional Columns

Many grid columns in the PowerShell Scripts view are hidden by default. To display additional columns, select the column chooser icon in the toolbar and select the desired columns.



Grid Columns

Script

Id

A unique identifier for the script, used when referencing it in Script Buttons, Surveys, or DMR reports.

Script Name

Displayed throughout the UI, including in the UI Buttons Panel. Also determines the corresponding log file name.

Category

An optional field for organising scripts. The Category automatically creates a folder in the PowerShell Tree view for better management.

Is Enabled

Controls whether the script is allowed to execute, without requiring unlinking from UI Buttons or Scheduled Tasks.

Description

An optional description for UI reference. Descriptions are not processed by the system elsewhere.

Edit Button

Opens a window to edit the full PowerShell script. All changes are tracked automatically, unless a Script Path is provided.

Script Path

For longer scripts, specify a file path (e.g., C:\scripts\myScript.ps1). Scripts referenced by path do not have their changes tracked by ManagementStudio. If both script text and a script path are provided, the script at the path takes precedence.

Note:

  • Scripts loaded from a path are not wrapped in the default API template and must establish their own API connection, but they receive the same arguments.

ManagementStudio checks for scripts in the following locations, in priority order:

  1. Explicit Path: Example: C:\scripts\myScript.ps1
  2. Project Scripts Folder: Example: [StorageFolder]\path\Scripts\myScript.ps1 if path is specified as path\myScript.ps1
  3. Automation Scripts Folder: Example: wwwroot\Automation\Scripts\myScript.ps1 if only the file name is given

Options

Module

Scripts should target a ManagementStudio module (e.g., Applications). Selecting a module filters available triggers and controls which scripts are accessible to UI Buttons. The module value is passed to scripts as the Module variable.

Run As

Determines the account context under which the script executes. Permissions and audit trails are aligned to this account. Only users in the Project Permissions \ Run Script As role are available; by default, the system API account is assigned.

Priority (hidden)

Used to determine script execution order when multiple scripts are triggered simultaneously. Lower numbers execute first.

Grant Access 1, 2, 3 (2, 3 hidden)

Defines the user role required to execute the script.

Schedule 1, 2, 3 (2, 3 hidden)

Associates the script with up to three Scheduled Tasks. Each Scheduled Task can trigger the script independently.

Trigger & Sub Trigger

Scripts can be assigned up to three different triggers based on events within ManagementStudio (e.g., application archived, process state change).

Note: To enable a script for more than three triggers, copy it to an additional row and configure further triggers.

Args 1, 2, 3 (hidden)

Allows passing up to three custom arguments to the script at execution time, enabling reuse and custom behaviour.

Log Args (hidden)

By default, all script arguments are logged. This can be disabled for frequently called scripts to reduce log file size.

URL Activation

Exec via URL & URL Exec Key

Scripts may be executed through specifically crafted URLs, suitable for integration with emails or DMR reports. This feature allows, for example, the creation of a button link in a DMR for direct script execution.

Args

Add args1, args2, and args3 as query parameters to pass values into the script:

http://<server>/<project>/p/a/script/<instanceId>/<scriptId>?ikey=<instanceKey>&skey=<urlExecKey>&args1=value1&args2=value2&args3=value3

Structure

Example HTML link:

<a href="https://<ServerUrl>/<ProjectId>/p/a/script/<InstanceId>/<ScriptId>?ikey=<Instance_RandomKey>&skey=<Script_UrlExecKey>" target="_blank">Unlock Slot</a>
  • Keyword:

    • [{Module}-UrlButton-Script-{ScriptId}-{Button Text}-{arg1}-{arg2}-{arg3}]
    • [{Module}-Url-Script-{ScriptId}-{Button Text}-{arg1}-{arg2}-{arg3}]
  • Example:
    [UM-Url-Script-99-Unlock Slot] will create a url that can be wrapped in a link 
    [UM-UrlButton-Script-99-Unlock Slot] will create a block of HTML as a button 

  • Raw URL Example:

    <a href="https://managementstudio.com/1/p/a/script/[UM-MigrationId]/99?ikey=[UM-RandomKey]&skey=ATKU0VBRKH" target="_blank">Unlock Slot</a>
    

DMR Expression Column Example

<a href="https://managementstudio.com/1/p/a/script/' + UserMigrations_MigrationId + '/999?ikey=' + UserMigrations_RandomKey + '&skey=ATKU0VBRKH" target="_blank">Unlock Slot</a>

Output Example

<a href="https://managementstudio.com/1/p/a/script/1000/999?ikey=ASDFASD&skey=ATKU0VBRKH" target="_blank">Unlock Slot</a>

Previous Versions

All versions of script text edits are automatically retained with author and timestamp. Use the chevron in the Prev. Ver column to select and restore previous versions.


Running Scripts

Surveys & Self-Schedule

Surveys and Self-Schedule forms can execute PowerShell scripts when submitted. Each form’s admin page includes a script editor. Scripts created via these forms also appear and can be edited from the PowerShell Scripts panel. Script names generated from these sources reflect the respective survey or Self-Schedule name and ID.

Calling Scripts in ManagementStudio

Scripts are not executed directly from this panel. They are called by:

  • Scheduled Tasks
  • Custom UI Buttons
  • System Events

Calling Scripts Outside ManagementStudio

Script Arguments

When called, each script receives a $ScriptArgs object containing contextual data and arguments. Use $ScriptArgs.Items, $ScriptArgs.ScriptArg1, $ScriptArgs.LogFile, etc., within the script.

ArgumentDataNotes
ScriptNameScriptName.PS1Name as defined in PowerShell Scripts panel
SourceTypeEventTriggerHow the script was called (UI Button, Scheduled Task, Event, etc.)
SourceNameUpdatedFurther source info (e.g., "Updated", "Created")
SourceId55E.g., ButtonId
RanByUserAdmin AccountAccount executing the script
RanAsUserAPI AccountAccount under which permissions/actions are evaluated
ProjectId1ID of calling project
ModuleApplicationsModule assigned in the PowerShell panel
Items1000,1001,1002List of IDs or objects being operated upon
AltItems2000,3000,54542Related object IDs
ScriptId1ID from the PowerShell Panel
ScriptArg1,2,3Option1Optional PowerShell Panel arguments
EventArg1,2Additional event-triggered arguments
UserInputInput from a UI button prompt
CallerInput2ESM plan number initiating the script
ScriptFolder\...\ScriptsThe script file path if loaded from file
ReportsFolder\...\ReportsPath to project reports
AutomationFolderAPI module path
LogsFolder\...\LogsPath to project log files
LogFile\...\Logs...Full script log file path
UtcOffset-3Time zone offset
StartTime...Script launch time
ServerIsWaitingReserved/not implemented
ApiUrl...API endpoint URL
ApiModule...Full path to the ManagementStudio API module
ApiToken...API access token

Further Support

For additional assistance, visit the ManagementStudio Service Desk to search the knowledge base or raise a new support ticket.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article