aweber
Posts: 52
Joined: Mon Jun 18, 2018 7:45 pm

pass parameters to attached PS custom action script?

Mon Apr 01, 2019 3:03 pm

Why is there a Parameters mechanism (textbox) to easily pass parameters to our Inline PS custom actions, but there is no such place to put parameters if we decide to use the "Run PowerShell Script File" custom action?

How do we pass parameters into the powershell script?

Catalin
Posts: 6537
Joined: Wed Jun 13, 2018 7:49 am

Re: pass parameters to attached PS custom action script?

Tue Apr 02, 2019 2:05 pm

Hello AJ,

The main purpose of the "Parameters" field from the "Run PowerShell inline script" custom action is to access properties from a deferred custom action (when the "Run PowerShell inline script" custom action has its execution time of "When the system is being modfied (deferred)").

The predefined "Run PowerShell inline script" was implemented before the "Run PowerShell script file" custom action and many issues were encountered while developing the "Parameters" field functionality. However, this is more stable now, this being the reason why we already have on our TODO list to add the "Parameters" field to the "Run PowerShell script file" custom action as well. We did not proceed in adding it because it was not requested at all until now. But since you have requested it now, I have increased its priority and hopefully it will be implemented in a future version of Advanced Installer.
How do we pass parameters into the powershell script?
In what regards this, you can simply get and set properties from within your PowerShell script file by using one of the following lines:

Code: Select all

$someVariable = AI_GetMsiProperty YOUR_PROPERTY
or

Code: Select all

AI_SetMsiProperty YOUR_PROPERTY <some_value>
However, this only works when the custom action's execution time is "Immediately". The main reason of this is because when setup enters the deferred stage, all the properties are set to empty strings. The exception to this rule is the special CustomActionData property which keeps its values through all of the stages even during deferred, rollback and commit. Please have a look on our "How to access installer properties from deferred custom actions" article for more information about this topic.

Hope this helps.

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

ipollock
Posts: 137
Joined: Wed Aug 31, 2016 10:46 am

Re: pass parameters to attached PS custom action script?

Mon Dec 06, 2021 5:39 pm

Can you add more than one property at a time in there?

Catalin
Posts: 6537
Joined: Wed Jun 13, 2018 7:49 am

Re: pass parameters to attached PS custom action script?

Tue Dec 07, 2021 10:58 am

Hello,

Sure thing, you can retrieve more than one parameter. Here would be a sample syntax:

Code: Select all

-firstPsParam [FIRST_MSI_PROP] -secondPsParam [SECOND_MSI_PROP]
for a PowerShell Inline Script custom action.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”