PowerShell Scripts

This article discusses the options for creating PowerShell reports and management tasks through SysKit.

PowerShell Scripts on the Administration tab are designed to make it as easy as possible for you to take control and simplify reporting and administration of your Windows environments.
If you navigate to Administration > PowerShell Scripts, you will find endless possibilities for the creation of new report and management scripts.
This section is completely different from the one on Inventory Reports > PowerShell Reports. It consists of Reports and Management Tasks subsections within which you can categorize the scripts you want to create.

Reports

This subsection contains all PowerShell scripts that always return results in the form of multiple columns / rows and are meant for reporting purposes. Saved and executed report scripts can return varying amounts of data, but these report scripts can also return ‘Error’ results for some computers.
Reports subsection comes with two report categories and three predefined PowerShell scripts for you to explore:

  • Computers by OUs – The script is located in the AD category. Note that it can only be executed on the Domain Controller(s) in a server environment.
    This report displays a list of all computers in a domain and their corresponding Organizational Units.
  • Installed Features – The script is located in the Roles and Features category. It can be executed on any monitored computer.
    This report displays information about Windows Server features that are available for installation and installed on the target computer(s).
  • Installed Roles – The script is located in the Roles and Features category. It can be executed on any monitored computer.
    This report displays information about Windows Server roles and role services that are available for installation and installed on the target computer(s).

PowerShell scripts saved as Reports, depending on the scripts’ purpose, will have multiple columns displayed, but some of the default columns are: Computer on which the script was executed, Date/Time at which the script was triggered, and Status in which the script returned from target computers.

Management Tasks

This subsection contains all PowerShell scripts that perform some kind of management task and only return details on whether the specified task was successfully completed or an error occurred. PowerShell scripts saved as Management Tasks will only have three columns displayed: Computer on which the script was executed, Date/Time at which the script was triggered, and Status in which the script returned from target computers.

Error results are returned from the target computers in the following cases:

  • If executing PowerShell script(s) on target computers with lower Operating System versions, which have a certain number of cmdlets available and do not support the usage of cmdlets available in the newer OS versions.
  • If PowerShell is not installed on target computers for some reason.
  • If PSRemoting is disabled on target computers for some reason.
  • If PowerShell command timed out on target computers for some reason.
  • If user has insufficient rights on target computers.
  • If other errors are thrown by Windows PowerShell.
Tip! If an executed report or management script has the Status marked ‘Error,’ you will be able to see the error message returned from the destination computer by hovering over the column marked ‘Error.’ This applies to all PowerShell Scripts.
    Tip! If run after another script functionality is enabled and an error occurs in the previous script, execution of all following scripts will not be performed.

     

    All PowerShell Scripts available on the Administration tab have the filter panel available to the right. It contains three filter types—Date Range, Computer Groups, and Computer—so you can filter your data more easily. Use the Date Range filter to select any day, week, month, or custom date range.

    Please note! You will not be able to see any PowerShell script data outside 30 days, unless you change the PowerShell Scripts Data Retention settings. The default is set to delete PowerShell script data older than 30 days.

     

    PowerShell is known as an excellent tool for automating repetitive tasks, so you can start building your report and management scripts using SysKit’s PowerShell Script editor. You can import PowerShell scripts into the wizard (with .ps1 extension only), write your own PowerShell code, and create some amazing reports and management tasks.
    With the built-in PowerShell Script Wizard, you can also import and edit PowerShell Script Modules with .ps1 and .psm1 extensions. A script module allows you to use a number of rules and cmdlets in your scripts. In simple terms, a script module is just a grouping of functions and code that can be applied to a specific group of scripts. PowerShell modules are actually highly recommended when writing PowerShell scripts, because they are created for applications such as Microsoft Exchange, Active Directory, VMware, etc., to manage all aspects of various applications.
    The PowerShell module feature within SysKit’s PowerShell Script Wizard allows the combining of multiple scripts to simplify code management, accessibility, and sharing.
    The PowerShell Wizard also comes with PowerShell Script Alerts, which are crucial for effective monitoring of any critical and important jobs that run in a server environment. SysKit will let you know when critical errors occur if you’ve configured the alert conditions for important PowerShell Scripts.
    PowerShell Script rows that match the applied conditions and have triggered an alert will be painted light yellow after the script executes. These rows will be exported to .csv format and included in the email attachment of the alert.

    We’ll break down how you can create report and management scripts in SysKit using PowerShell Script Wizard.

    1. In Step 1, specify the PowerShell script type you wish to create. The wizard offers two different script types: PowerShell Report and PowerShell Management Task.
      Tip! The first option can be useful for retrieving a wealth of information about a server’s configuration, usage, or performance. The second option is useful for performing various administration and maintenance jobs.
    1. In Step 2, simply enter the PowerShell script name and select the desired category. Note that based on the script type you have selected in the previous step, your script will be added to the corresponding category. The report category option will help you categorize your reports and management tasks so you can manage large amounts of scripts more easily.
      For more advanced scripts, you can also enable the CredSSP authentication to avoid double-hop problems. In cases where a PowerShell script may need to access resources outside the remote server machine, the credentials must be delegated to the target machine.
      How to enable the CredSSP authentication
      If the entered PS script requires the credentials to be delegated and you have enabled the CredSSP option, the error dialog will be shown upon validation of the script. It will guide you on how to switch to custom credentials. Just click the Configure button in this dialog, and the Edit domain dialog will be shown. Select the Specify credentials option and re-enter the service credentials.
      Tip! It is recommended that you enable the Use credentials only for PowerShell option as the custom credentials are meant for authentication when monitoring computers from untrusted domains.
      See the Configuring CredSSP for use with PowerShell in SysKit article to learn more.
    1. In Step 3, you will need to enter the PowerShell script you want to use to create reports or management tasks. Here you can also import the script modules whose members can contain functions, variables, and more. To avoid incorrectly generated reports, the report script first needs to be tested on a selected computer. SysKit will run it against the computer that you specify.
      If you have selected the management task script type in the first step, the management script will only be validated for syntax errors.
      All referenced modules will also be validated in both cases before the wizard returns and displays the results of the script and modules you have run. After entering script, click Next> to see the results.
      Please note! If you have troubles with writing script, or you want to know more about PowerShell rules and limitations, please read this article.
      See the article on the PowerShell script modules to learn more how and when to import and use script modules.
    1. In Step 4, if the script and module syntax are valid, the results of the report script will be returned in a grid view. Please verify whether the script returned the desired results, then continue to the next step. As mentioned previously, if you are creating a management script, your script will only be validated; you will not have this step.
      Please note! The approximate size of the query result can wary depending on the entered script purpose. Take into consideration that large query results can significantly increase server resource utilization.
      Please note! If an entered PowerShell query is returned without results after validation in PowerShell wizard, it cannot be saved.
    1. In Step 5, you will need to select the computers you want to run the PowerShell script on.
      Created PowerShell script can be scheduled to run on:
      • All computers;
      • Specific computers; or
      • Specific computer groups.
      Please note! Query results may vary depending on the PowerShell version used on a specific computer.
    1. In Step 6, you will need to specify the conditions that will trigger the PowerShell script.
    2. The following schedule options are available:

      • Manual only—the script will be executed only when the Run button is clicked.
      • Automatic—the script will be executed automatically on a defined schedule, which has two types: Recurrence or After another script.
      Tip! If the Recurrence option is selected, you will be offered several recurrence types: one time, minutely, hourly, daily, weekly, monthly, and quarterly. Here, you can select the start date and time for the selected recurrence type.
      Tip! If the After another script option is selected, you will be offered a drop-down menu that contains all PowerShell scripts available in SysKit. The script for which you configure the trigger will be executed after the script selected from the drop-down.
    1. In Step 7, you can enable and configure conditions for alerts sent after the script finishes. SysKit will detect and set the PowerShell script column types and allow configuration of real-time alerts based on the desired conditions. A PowerShell script can return different column types. The ones that are discoverable by SysKit are String, DateTime, UInt64, UInt32, Int64, Int32, Double, Boolean, and Decimal.
    1. In Step 8, if the alert condition is met you can choose whether you want to be notified immediately. Alternatively, you can be notified if the state remains unchanged after the specified time interval has passed. Note: in both cases, you will receive an alert when the condition is met and you will also receive an email after everything returns to the normal state.
      SysKit will generate a .csv file, which contains all the data matching the applied conditions and include it in the email attachment of the alert.
      Here you can also select whether to send alerts to email addresses defined in the Options dialog or you can specify different ones.

    All created and saved PowerShell scripts, depending on the script’s type, will be added to the Administration tab > PowerShell Scripts > Reports or Management Tasks group.

     

    PowerShell Scripts Ribbon

    Ribbon provides a set of basic functions for managing the created or imported report and management scripts.

    • Create – Create a new PowerShell report or management task.
    • Edit – Edit the selected PowerShell report or management task.
    • Delete – Delete the selected PowerShell report or management task.
    • Edit Trigger – Edit the conditions that will trigger the PowerShell script.
    • Download Scripts – Download and import the predefined PowerShell scripts from Acceleratio’s repository.
    • Refresh – Refresh items in the left navigation panel, filters, and main view.
    • Default Layout – Reset the current layout of the main view to the default layout.
    • Run – Run the selected PowerShell script on target computers.
    • Run on Selected Computers – Run the selected PowerShell script outside its scheduled hours — on demand and on different computers or computer groups.
    • Enable – Enable the selected PowerShell script for execution.
    • Disable – Disable the selected PowerShell script for execution.
    • Export – Export the script results and retrieved information to PDF, Excel, HTML, or CSV files.

    This dialog shows all available PowerShell scripts created or imported through SysKit. Scripts are grouped by type to two folders, like in reports’ left navigation: Reports and Management Tasks. The script execution is performed periodically, and you are able to configure the triggers as you wish. When you configure each script according to your preferences, it will run periodically as configured. You can also manually run specific or multiple scripts, which will be executed at the next tick of service.

    The following options are available:

    • Run, Enable, Disable, Edit Trigger – previously described in the upper part.
    • Select Computers – Use this option to configure the computers on which to execute the script(s).
    • Remove – Use this option to delete the selected script(s).
    • Add, Edit, and Remove Category – Use these options to manage the created categories and subcategories for your scripts. Note that the Remove Category button will delete the whole category with all its containing scripts.
    • Refresh – Use this option to refresh the dialog items and script status.

    All of the available options for script configuration and execution can be managed easily with the multi-select option supported in grid-view.

    The grid-view in Manage Scripts displays the following elements:

    • Name – the name of the script.
    • Triggers – information about the script’s execution schedule.
    • Last Run Time – the last time a script was executed.
    • Next Run Time – the next time a script will be executed. It depends on the configured trigger conditions.
    • Run On – Indicates whether the script is configured to run on all or specific computers or computer groups.

    The Script icon on this dialog will change its appearance, depending on the script’s state, which can be disabled or executing. A green arrow will be shown while the script is executing.

    This dialog provides options for importing and configuring PowerShell scripts in SYSpr format. PowerShell scripts are generated in this format when our development team creates them upon our customers’ requests.

    When importing previously created PowerShell scripts in SYSpr format, simply select the PowerShell report definitions you want from your local or network drive, assign the script(s) to desired categories, specify the computers on which the scripts should be executed, and change the conditions that will trigger the scripts. The category option will help you categorize your scripts so you can manage large amounts of different scripts more easily.

    When specifying the computers on which to run the imported PowerShell script(s), the following options are available:

    • All computers;
    • Specific computers;
    • Specific computer groups.

    When specifying the conditions that will trigger the imported PowerShell script(s), the following schedule options are available:

    • Manual only – the script will be executed manually when the Run button is clicked.
    • Automatic – the script will be executed automatically on a defined schedule, which has two types: Recurrence or After another script.

    If the Recurrence option is selected, you will be offered several recurrence types: one time, minutely, hourly, daily, weekly, monthly, and quarterly. Here, you can select the start date and time for the selected recurrence type.

    If the After another script option is selected, you will be offered a dropdown menu that contains all PowerShell scripts available in SysKit. The script for which you configure the trigger will be executed after the script selected from the dropdown.

    All imported PowerShell report definitions, depending on the scripts’ type, will be added to the Administration tab > PowerShell Scripts > Reports or Management Tasks group.

    Tip! When you are importing or exporting a PowerShell report definition, all its script modules, if any, will be imported / exported as well. All imported script modules can be managed through the Manage modules dialog in the Enter PowerShell step of the PowerShell Script Wizard.

    This dialog enables you to browse through and download the available predefined PowerShell scripts from Acceleratio’s repository. There are around fifty PowerShell scripts categorized by purpose.
    Most of the available PowerShell scripts can run on all types of servers while others are tied to a specific server role—such as Domain Controller, IIS, or Hyper-V—or have to be executed on the local machine. It is very important to read the script description on the right side.

    If you select a script from the list, the following script information will be displayed:

    • Name – the name of the script.
    • Description – the description of the script. It is very important to read the description, as it may clarify the purpose of the script and the specific server role that the script should be executed on.
    • Version – scripts can be changed and updated with more advanced functionality by our product team.
    • Author – the name of the author.
    • Date Published – the date when the script was published.

    Depending on which tab is selected, the available options change their purpose:

    • Search box – Use this option to search through the available scripts. The script description will also be included if it matches the entered criteria.
    • Online tab – Displays scripts that are ready for installation.
    • Installed tab – Displays a list of scripts that are already installed. If you want to remove installed scripts, just select them and click the Remove button. Afterwards, the script(s) and all related execution data will be deleted.
    • Updates tab – Displays a list of scripts that have been updated by our product team. If you want to update installed scripts, just select them and click the Update button. Afterwards, the script(s) will be replaced with new ones, keeping all the previously defined user settings for target computers, triggers, alert conditions and options, etc.

    When downloading available PowerShell scripts, simply select the PowerShell scripts and click the Install button. After the PowerShell scripts have been downloaded, the success dialog will appear, asking you whether you want the default settings applied or whether you wish to change these settings.
    If you choose the Manage Scripts button, the corresponding dialog will open and newly downloaded PowerShell scripts will be marked with a green arrow. The scripts will also appear in the left navigation within their corresponding folder structure.

    If you click SysKit’s status bar on the lower left, information about currently running system jobs and PowerShell scripts will be shown. You can use this progress bar to check for the PowerShell scripts’ execution statuses and determine whether each script is still in the queue, it’s being executed or it was recently executed.

    Please note! The PowerShell status bar will always show execution history for the last five minutes.