Today we released a new service build of PowerShell Studio 2018 (v5.5.151). This service build is included as part of the regular update cycle for our subscribers.
This service release introduces changes to our file templates format, new file templates, custom actions for your installer, and more.
Custom Actions for MSI Installers
You can now specify custom actions for your MSI Installers. Custom Actions allow you to run custom scripts and tools during the installation process.
For more details on using Custom Actions, refer to the following article:
Service Installer Option
PowerShell Studio now allows you to create installer for service executables. You can use this option in conjunction with the service packager engine.
For more details on the Service Installer, refer to the following article:
Updated New File and New Project Dialogs
The first thing you will notice when creating a new file or new project is the redesigned dialogs that allow you to select the file or project templates.
In the upper left-hand side are the categories for the file templates. You will find a PowerShell category that lists all PowerShell script files and a sub-category for form templates.
If you select the top node, in this case, Files, it will list all of the templates.
You can use the search field to search the template titles and their tags (see below).
Select the Files node to search all available templates regardless of category.
The small text located next to the template names are tags/keywords that describe the contents of the particular template.
For example, a form template may have the following tags:
PowerShell, Form, Grid, Search
These tags let you know that this particular template is a PowerShell script that has a GUI with a Grid and has Search capabilities.
Tags can also be used to filter out file templates by language.
New File Templates
We added several new templates to PowerShell Studio:
Service Script Template
This template contains the necessary functions to create a Windows service script executable.
PowerShell Class Template
This template contains an example PowerShell class. When you use this template, PowerShell Studio immediately allows you to rename the class directly within the editor.
If you add the class template as part of a project, it will use the specified file name as the default name of the class.
C# File Template
This template creates an empty C# file. You can use this template as a quick way of writing C# code for the Add-Type cmdlet.
Text File Template
This template creates an empty text file.
New Template Format
The new features mentioned above are possible because of the new template format (.pstemplate) introduced in this build.
Note: PowerShell Studio will automatically convert your existing templates to the new pstemplate format.
The templates are stored in new directories:
|Template Type||New Template Directory|
|File (includes psf files)||[Template Directory]\File Templates|
|Grid||[Template Directory]\Grid Templates|
|Project||[Template Directory]\Project Templates|
Note: Form psf templates are now stored with the other file templates.
We will cover the template format in more detail in a later article.
New Template Variables
This service build also introduces new template variables:
Inserts the file name without the extension.
Inserts the snippet that comes with the template script. This is handled automatically when creating a template.
Inserts the snippet with the matching shortcut. This snippet must be present in the Snippet Panel and is not included with the template.
%SNIPPET:MSGBOX% will insert the message box snippet when the template is first loaded.
Important: Templates only trigger the first %SNIPPET% variable—multiple uses of the variable will be ignored.
Template Variable Formatting
When using variables in your templates, it may be necessary to format the value for particular circumstances. For example, in PowerShell Manifest (psd1) the template variables are often contained in quotes, thus requiring the value to be formatted/encoded to prevent it from breaking the existing string.
To encode the value, use the following format:
Where VARIABLE is the name of the variable and FORMAT is the name of the formatting type.
|PSSingle||Format for a PowerShell single quoted string.|
|PSDouble||Format for a PowerShell double quoted string.|
|C||Format for C/C++ string.|
|HTML||Format for HTML string.|
|Object||Format for object names (class/variable/members).|
For example, to format the USERNAME into a single quote PowerShell string use the following:
If you want the variable to be a name for an object such as a class name, then use the Object format:
Note: In some cases variables may return an empty string and this may be undesirable, especially when the variable is used for an object’s name. The new template format allows you to set defaults to handle cases like these. This will be discussed in more detail in a later article.
Creating a New Template
You still create templates using the same Ribbon > File > Create Template command.
The Create File Template dialog has been updated to support the new features mentioned above.
You can specify the template’s tags when creating a new template. For example, if you create a template for an Azure script, you specify an Azure tag for that template. Users can then search for the tags when creating a new file.
Note: PowerShell Studio will automatically set some default tags based on the file extension.
You can specify the template type. There are two options available:
|File||The template is used for new files.|
|Grid||The template is used when exporting a GUI from the Database Browser or the WMI Browser.|
In order to select a Grid template, the psf file must contain a DataGridView control.
Note: The dialog will show a warning that you need to use the %ResultsFunction% and %ResultsFunctionCall% template variables for the Grid template.
If you specified the %SNIPPET% variable in your script, the dialog will present you with a field allowing you to select the desired snippet to trigger when the template is loaded. The selected snippet will be included with the template.
Once the desired information is entered, press the Save button and a Save Dialog will appear. The folder that you choose to save the template to will determine the category (see below).
Templates can now be organized by categories (folders) to make it easier to browse your existing templates.
For example, PowerShell specific templates are stored in a PowerShell folder:
[Template Directory]\File Templates\PowerShell>
PowerShell GUI forms (psf) are stored in a Forms folder under the PowerShell category:
[Template Directory]\File Templates\PowerShell\Forms
You can create new categories by simply creating a new folder when saving your template.
Start Page – Subscription Status
If you are like me and are bad at remembering to renew software, this feature is for you. The Start Page will now remind you if your subscription is about expire.
The Start Page also provides a button to log into your account for renewals.
New Control Set
We added a new control set: ComboBox – With History
The control set allows you to persist the history of the combo box. For example, if you have a search field, this combo box can maintain the users search history between sessions. The control set comes with two helper functions:
This function saves the contents of the combo box in a history file. You must invoke this function in your script in order to save the history. For example, if you have a search button, it can invoke the function when the button is pressed. The history file is saved to the following location:
If the script is run within a packaged executable host, it will then use the Company and Application name instead:
ApplicationDataFolder\Company Name\Product Name\ComboBoxName.history
Override the default file by using the Path parameter of the function.
Call this function to restore the history of the combo box. The control set automatically invokes this function as soon as the control becomes visible. Override the default file by using the Path parameter of the function.
PowerShell Studio now displays how many controls reference the event when you hover over the event variable:
This feature provides a quick way of determining if your events are wired or not.
New Stock Icons
We added new flat stock icons for your packager executable (icons courtesy of Axialis).
On Hover Parameter Set Information
This build trims the number of parameter sets that are displayed when hovering over a command.
Trimming the parameter sets prevents the pop-up from covering the screen when hovering over a command that contains a large number of parameter sets. A message at the bottom will denote how many more parameter sets the cmdlet has.
Collapse Regions On Load Behavior
We modified the Collapse regions on load option behavior to collapse the Include nodes that are configured by the user under Ribbon > Home > Editor > Regions > Include:
When you load a script file, the editor will collapse the checked nodes instead of only collapsing regions.
Project Load Speeds
We further improved load speeds of projects that contain large amounts of psf files.
Export Module – Improved Cache Speed
When you export your module project, PowerShell Studio refreshes the cache for the module.
The caching process now completes in a fraction of the time it took in previous versions.
Please continue providing your feedback. Many of the new features included in the service builds are suggestions from users like you. Submit your suggestions or feature requests on the Wish List and Feature Requests forum or the new Feature Requests page.
You can view the complete service build log here.