SuperDev
Posts: 10
Joined: Thu Oct 13, 2022 5:38 pm

PowerShell Inline Script

Hello,

I am reaching out because I need help running an Invoke-Sqlcmd in the Powershell Inline Script to remove a DB when program is uninstalled. I want to pass the sql connection properties into this PS Script to directly reference those values after the user inputs them into a dialog box. I referred to the powershell documentation in Advanced Installer but still need more clarity on the structure needed to facilitate this. I have attached my project file, please let me know if anymore information/clarity is needed on my end thank you and have a great day!
Attachments
SQL DB Test.aip
(21.48 KiB) Downloaded 148 times
Liviu
Posts: 1042
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: PowerShell Inline Script

Hello,

You've set the Execution Time for your custom action to "Immediately". Please note that the parameters value field is used for deferred custom actions.

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)").

For more details, please take a look at our Run Inline PowerShell Script article.

To get a property during an immediate action, you need to include a line with the following syntax in your script:

Code: Select all

$propValue = AI_GetMsiProperty YOUR_PROP
You can adjust your script based on the immediate action, or you can change its execution to "deferred".

In the article above you have an example of accessing properties for deferred custom actions - "Getting a property value into a script (for deferred custom actions)" section.

Hope this helps! If you have any other questions, please don’t hesitate to contact us.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
SuperDev
Posts: 10
Joined: Thu Oct 13, 2022 5:38 pm

Re: PowerShell Inline Script

Awesome, Thank you! I have adjust the syntax as recommended, but still receiving an error when trying to test out the script. I am certain I am doing this step the wrong way and will upload my project file. I truly appreciate your help!
Attachments
SQL DB Test.aip
(21.71 KiB) Downloaded 145 times
Catalin
Posts: 6585
Joined: Wed Jun 13, 2018 7:49 am

Re: PowerShell Inline Script

Hello,

Most likely, in your case, the properties are not available during the uninstall.

If you want the value that your user inputs at install time to be available at uninstall time, you can try to set the properties as "persistent".

How do I make the properties in the package keep their values during Maintenance or Upgrade?

Additionally, since your custom action modifies the system, you may want to schedule it as "deferred" (its "Execution Time")

If your custom action requires elevation, you can also check the "Run under the LocalSystem account with full privileges (no impersonation)" option.

Here is how your custom action can look like:
Screenshot_87.png
Screenshot_87.png (81.13 KiB) Viewed 6617 times

Hope this helps!

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

Return to “Common Problems”