Script explorer
The Script Explorer in Master Wrapper is a built-in tool designed to simplify working with PowerShell code inside PSAppDeployToolkit projects. It helps create, manage, and reuse script components without leaving the Master Wrapper interface. Script Explorer is divided into three main sections: Script builder, Custom snippets, and Built-in snippets, each offering different capabilities.
Script Builder
The Script Builder allows generating ready-to-use PowerShell commands for common deployment tasks, such as modifying the registry or managing firewall rules. Instead of writing code manually, users can select options in the interface, and Script Builder will generate the corresponding PowerShell commands automatically.
Add registry values from .reg file
This feature allows converting .reg
files into PowerShell commands used in PSAppDeployToolkit scripts. It eliminates the need to manually write registry manipulation commands by automatically generating them based on the imported file.
How it works:
- Click Browse .reg and select a registry export file from your system.
- Master Wrapper will parse the
.reg
content and automatically convert it intoSet-ADTRegistryKey
commands for installation andRemove-ADTRegistryKey
commands for uninstallation. - If the registry keys are under
HKCU
, the tool will useInvoke-ADTAllUsersRegistryAction
to ensure that the changes apply to all user profiles during a SYSTEM-level installation.
Generated code:
- Install code: Appears in the top code window and contains
Set-ADTRegistryKey
commands. This is meant to be copied into the Install or Repair section of the deployment script. - Uninstall code: Appears in the bottom code window with
Remove-ADTRegistryKey
commands. This should be added to the Uninstall section of your script to clean up registry keys if needed.
Add Windows Firewall rules
This feature simplifies the creation of Windows Firewall rules directly from the Master Wrapper interface by automatically generating the required PowerShell commands. It removes the need to manually write New-NetFirewallRule
commands, ensuring consistency and saving time during package creation.
How it works:
- Browse target file – Click this button to locate and select the executable (
.exe
) file for which the firewall rules should be created. The full path will automatically populate the Path field. - Name – Enter a display name for the firewall rule. This name will be used when creating and removing the rule.
- Direction – Choose whether the rule applies to Inbound, Outbound, or both types of network traffic.
- Profiles – Select the network profile(s) the rule should apply to: Public, Private, or Domain.
- Protocol – Choose TCP, UDP, or both, depending on the application requirements.
Once the details are entered, Master Wrapper automatically generates the PowerShell commands needed to create the firewall rules.
Generated code:
- Install code – The generated
New-NetFirewallRule
commands will appear in the install section. These commands can be copied into the Install or Repair section of the deployment script. - Uninstall code – The corresponding
Remove-NetFirewallRule
command is generated to ensure the rule is removed during uninstallation. This should be added to the Uninstall section of the script.
Custom Snippets
This feature enables users to save specific code snippets, for example - copy files, remove registries, etc. This will save you time the next time you will need to write this code again.
- Create a snippet
- Specify snippet name
- Set the prefix which will be used to invoke the snippet
- Add a description that will be displayed in IntelliSense.
- Enter your PowerShell script (Note that the snippets use a specific TextMate Snippets syntax)
- Save
- Start typing the prefix and once it has been selected, just press Tab for the code to be inserted.
Built-in Snippets
The Script Explorer also provides a collection of built-in snippets that include common PowerShell structures and commands. These predefined snippets help speed up script creation and reduce errors by providing ready-made code templates that can be inserted instantly.
Available built-in snippets:
- Comment Block | block-comment – A multi-line comment.
- do-until | do-until – Runs a statement list repeatedly until a condition is met.
- do-while | do-while – Runs a statement list repeatedly as long as a condition is met.
- else | else – Defines what is done when all if and elseif conditions are false.
- elseif | elseif – Provides an alternative path when an if condition is false.
- Enum | enum – An enumeration is a distinct type that consists of a set of named labels called the enumerator list.
- for | for – Creates a loop that runs commands in a command block while a specified condition evaluates to true. A typical use of the for loop is to iterate an array of values and operate on a subset of these values.
- for-reversed | forr – Reversed for loop snippet.
- foreach | foreach – Iterate through a collection, assigning a variable to the current item on each loop rather than using the automatic variable
$PSItem
. - foreach-item | foreach-item – Quicker definition of foreach. Highlight the variable name of the collection you want to use and type ‘item’ then press Tab.
- Hashtable | hashtable – A key/value store that is very efficient for finding and retrieving data.
- Here-String | hsHere-string – Escape all text but evaluate variables.
- Here-String (Literal) | hsliteral-here-string – Escape all text literally.
- if | if – Run code blocks if a specified conditional test evaluates to true.
- PSCustomObject | pscustomobject:[PSCustomObject] – Create a custom object from a hashtable of properties.
- Region Block | region – Region block for organizing and folding your code.
- splat | splat – Use a hashtable to capture the parameters of a function and pass them concisely.
- switch | switch – Equivalent to a series of if statements but simpler. The switch statement lists each condition and an optional action. If a condition obtains, the action is performed.
- try-catch | try-catch – Attempt a block of code and if a terminating exception occurs, perform another block of code rather than terminate the program.
- try-catch-finally | try-catch-finally – Attempt a block of code and if a terminating exception occurs, perform another block of code, finally performing a final block of code regardless of the outcome.
- try-finally | try-finally – Attempt a block of code and perform an action regardless of the outcome. Useful for cleanup or disconnecting active sessions even if there was a terminating error.
- while | while – Repeatedly perform an action after verifying a condition is true first.