Adding PowerShell Custom Actions

<< Click to Display Table of Contents >>

RayPack > 7.3 u6 > User Guide > PackDesigner > MSI / MST / RPP Based Projects > Advanced Mode > Custom Actions > Add a New Custom Action 

Adding PowerShell Custom Actions

PowerShell custom actions are exclusive feature that RayPack builds on top of the Windows Installer technology. The usage is similar to native scripting languages (.vbs or .js), with certain limitations.

 

Three source types are allowed: binary table, inline script and a Windows Installer property. It is not possible to start a script deployed with the package.

The whole content of a script will be started. It is not possible to start a particular function.

Only Immediate and Deferred execution is supported. Rollback and Cleanup custom actions are not supported.

 

PowerShell script editor has a standard set of functions.

 

ps editor

 

Load from file... - Loads a content of an existing .ps1 file.

Snippets - A dropdown of reusable content, scripts, and snippets.

Edit with default application - A split button opening the current script in external editor (default) or one of editors that is associated to open .ps1 files.

 

The text editor offers syntax highlighting for PowerShell and line numbers feature.

 

Working With MSI Session and Properties

PowerShell script executed from RayPack environment as a Custom Action has special capabilities to access (read and modify) session properties and its methods. In order to access the session, use predefined object $msiSession. The methods provided by the session are described in the MSDN documentation of the automation interface: https://msdn.microsoft.com/en-us/library/windows/desktop/aa367810(v=vs.85).aspx.

 

Reading MSI Properties:

For a quick access to a value of an MSI property, use the following code sample:

 

$productCode = Get-MSIProperty "ProductCode"

 
This will read a value of ProductCode and save it in productCode variable. Similar functionality can be also achieved by a direct access to the MSI session.

 

Writing to MSI Properties

In order to save the value back to the MSI:

 

Set-MSIProperty "MyCustomProperty" "Value Of My Property"

 

Similar functionality can be also achieved by a direct access to the MSI session.

 

Expanding Strings

In order to expand an MSI string (for example to get the path to a file myFile.exe):

 

$expandedValue = $msiSession.Format("[#myFile.exe]") 

 

Working With Snippets

Default installation of RayPack has a set of snippets preinstalled.

 

ps snippets

 

Pressing the name of the snippets inserts its content to the editor. Hovering the mouse cursor over the name reveals the content to be inserted.

 

Snippets are stored in the following location:

 

<PackPoint>\Snippets\PowerShellSnippets.xml

 

 Each snippet has a name and a content. Use any XML or text editor to add or customize the default set of snippets.