Next Topic

Previous Topic

Book Contents

Script Editor

The Script Editor creates and maintains customizable scripts that perform specialized tasks on managed machines. A number of pre-defined scripts are distributed with the VSA. Additional pre-defined scripts can be downloaded from the Kaseya user forum. These scripts can be used as is or customized by administrators. Scripts can be maintained using the Script Editor or imported and exported as text files and edited in any text editor.

Scripts are organized by three main statements:

  1. Each script begins with an IF statement.
  2. If the statement is true, the THEN statement is executed.
  3. If the statement is false, the ELSE statement is executed.

Drop down lists provide the set of IF-THEN-ELSE parameters appropriate for each statement.

Operating System Detect

When writing a THEN-ELSE statement, you can select the operating system the script will execute on. This parameter is useful when you want to write one script that can be executed on different operating systems. For example, directory paths in Windows and Macintosh can require different directory path syntax in order to work correctly. Creating two separate script steps within the same script for All Windows Operating Systems and a Mac OS X operating system, avoids having to create an extra script for a separate operating system.

Guidelines

Use the following guidelines when constructing a script:

  • Multiple steps can be defined under either the THEN statement or ELSE statement.
  • If no conditional statement is required, set the IF statement to True and define one or more steps underneath the THEN statement and no steps underneath the ELSE statement.
  • Each script can have only one IF statement. Nest IF statements by adding a step underneath the THEN or ELSE statement and use the Execute Script command. There is no limit to the number of nested scripts allowed.
  • When nesting scripts, only the top level script has to be scheduled to run.
  • Launch scripts written in other scripting languages by using the Execute File or Execute Shell Command.

Using Variables

Use variables to store values that can be referenced in multiple script steps. Variables are passed automatically to nested scripts.

  • Variables are created using two methods:
    • Script Variables - Use the Get Variable command within a script to create a new variable name without any special characters. Example: VariableName. In subsequent steps, including steps in nested scripts, reference the variable by bracketing the variable name with the # character. Example: #VariableName#. Scripts variables cannot be referenced outside of the script or nested scripts that use them.
    • Managed Variables - Use the Variable Manager to define variables that can be used repeatedly in different scripts. You can maintain multiple values for each managed variable, with each value applied to one or more group IDs. Managed variables cannot be re-assigned new values within a script. Within a script, reference a managed variable by bracketing the variable name with the < and > character. Example: <VariableName>.
  • Reserved Characters - Because the <, > and # characters are used to identify variable names, these characters must be entered twice as regular text in a command line. For example the following command c:\dir >> filelist.txt is interpreted at script runtime as c:\dir > filelist.txt.
  • Automatic SQL View Data Variables - SQL view parameters are available as automatically declared script variables. Use the format #SqlViewName.ColumnName# or #SqlViewName/ColumnName/Machine.GroupID# in a script to return the value of a dbo.SqlView.Column. If the optional machine ID is omitted, then the value for the agent executing the script is retrieved. Automatic variables enable you to skip using the GetVariable command with the SQL View Data option.
  • GetVariable SQL View Data Command - Use the GetVariable command with the SQL View Data option to create a new script variable and set it to the value of a dbo.SqlView.Column value. Use the format SqlViewName/ColumnName/mach.groupID or SqlViewName/ColumnName. See System > Database Views for a list of the SQL views and columns that are available.

Import Script...

Click the Import Script... link to display the Import Script popup window. Click Browse... to select the text file to be imported. Click Import to load the script into the Script Editor.

Note: Importing new scripts are always imported as private scripts. They can be shared or made public afterwards.

Export Script...

Click the Export Script... link to display the script in text format in the Export Script popup window. You can copy it to the clipboard or download it to a text file.

Manage Files...

Click the Manage Files... link to display the Manage Files Stored on Server popup window.

Manage Variables...

Click the Manage Variables... link to display the Variable Manager popup window.

Take Ownership...

You can't edit a public script you don't own. Click the Take Ownership link to display the Save, Rename... and Delete... buttons. Otherwise you can make a copy of the current script using the Save As... button.

Share...

You can share scripts you own with other individual administrators, administrator roles, or make the script public to all administrators.

Note: A master administrator can take ownership of a script and change share rights.

Save As...

Select Save As... to save a script under a different name. The script name must be less than 64 characters in length.

Save

Select Save to save changes to a script.

Rename

Select Rename to rename a script.

Delete

Select Delete to delete a script.

Script Notes

Enter any notes about the script.