We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

pghprogrammer4
Posts: 1
Joined: Fri Apr 12, 2019 1:33 am

Difficulty testing Powershell script file custom actions due to MSI cmdlets

Our company has multiple Powershell custom actions that we would like to unit test using Pester. We are having trouble doing so due to the atypical behaviors of the cmdlets AI_GetMsiProperty and AI_SetMsiProperty. These are the approaches we've considered/tried:

1. Wrap AI_GetMsiProperty in a function to mock the function: AI_GetMsiProperty won't accept variables for values
2. Wrap AI_GetMsiProperty in a module and import the module: I do not believe Advanced Installer will pick up external modules. Also, same problem as in #1.

Additionally, mocking validation appears that it won't work because AI_GetMsiProperty does not have any named parameters, so we can't validate using Pester's ParameterFilter syntax. I tried using using Get-Command during installer execution to find AI_GetMsiProperty/AI_SetMsiProperty property names, and while we did see something such as $name $value for AI_SetMsiProperty and $name $test1 for AI_GetMsiProperty, attempting to call AI_GetMsiProperty -name <PROPNAME> did not work. Finally, I get a CommandNotFoundException when I attempt to mock the cmdlets by themselves.

My general question is: has anyone had any luck mocking the cmdlets with Pester? Are there any guidelines for how we can test Powershell scripts that use the get/set MSI cmdlets?
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Difficulty testing Powershell script file custom actions due to MSI cmdlets

Hello and welcome to Advanced Installer forums,

First of all, please keep in mind that AI_GetMsiProperty and AI_SetMsiProperty are not PowerShell cmdlets. They are predefined custom functions. Here is how it actually works:

At install time, when you are using a "Run PowerShell script file" custom action, the script file is saved into a temporary location. Then we open the script file in edit mode, parse its content and, when either "AI_GetMsiProperty" or "AI_SetMsiProperty" is met, we expand that by calling a native C++ .dll function which is embedded in your project at build time.
... AI_GetMsiProperty does not have any named parameters ...
Indeed, these functions do not accept any parameters. The syntax for them is as it follows:

AI_GetMsiProperty YOUR_PROPERTY

or

AI_SetMsiProperty YOUR_PROPERTY <your_value>

With that being said, I am afraid you can not perform a unit testing on a PowerShell script file that contains the AI_GetMsiProperty and the AI_SetMsiProperty functions.

Please let me know if there is anything else I could help you with.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”