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.

  • Two Methods for Creating Variables:
    • 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>.
  • Where Used - Once variables are created you can include them, in their bracketed format, in any text entry field displayed by an IF-THEN-ELSE dialog box.
  • Case Sensitivity - Variable names are case sensitive.
  • 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.
  • Types of Variable Values Possible - The following are the types of variable values typically obtained by using the Get Variable parameter.
    • Registry Value - Data from the specified registry value on the managed machine.
    • File Content - Data from a specified file on the managed machine.
    • Constant Value - Specified constant as typed in the script editor.
    • Expression Value - Specify an expression that consists of script variables and six mathematical operators +, -, *, /, (, and ) that are evaluated and assigned to a new script variable. For example, ((#variable1# + #variable2#) + 17.4) / (#variable3# * 4). The script variables must contain numeric values.
    • Agent Install Directory Path - Directory in which the agent is installed on the managed machine.
    • Agent Install Drive - Drive in which the agent is installed on the managed machine, such as c:\.
    • Agent Temp Directory Path - Temporary directory on the managed machine as specified on the Temp Directory function on the agent tab.
    • User Temp Directory Path - The temporary directory for the user currently logged in on the managed machine. This path is the expansion of the %TEMP% environment variable for the currently logged in user. If no user is logged in, it is the default Windows temporary directory.
    • Machine.Group ID - Machine ID of the agent executing the script.
    • File Version Number - Version number from the property of the specified file on the managed machine.
    • File Size - Size in bytes of the specified file on the managed machine.
    • File Last Modified Date - Date of the specified file on the managed machine in the format of yyyy/mm/dd hh:mm:ss.
    • SQL View Data - 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. If the optional machine ID is omitted, then the value for the agent executing the script is retrieved. If ColumnName contains a space, surround it with square brackets. Example: vSystemInfo/[Product Name]. See System > Database Views for a list of the SQL views and columns that are available.

      Note: - Automatic SQL View Data Variables - SQL view parameters are available as automatically declared script variables. Automatic variables enable you to skip using the GetVariable command with the SQL View Data option. Use the format #SqlViewName.ColumnName# in a script to return the value of a dbo.SqlView.Column for the agent executing the script.

    • WMI Property - A WMI namespace, class, and property. The format of the specified WMI property is NameSpace:Class.Property. For example, root\cimv2:Win32_OperatingSystem.FreePhysicalMemory.

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.