Hello,
I am trying to share with you, a short tutorial to use PowerShell Custom Action. Please, let me know if there are some mistakes or misunderstanding.
Pre requirement :
- PowerShell v1 or more (in my case i have v2)
- InstallShield v2012 or with powershell module (in my case i have v2012)
- Run MSI file as Admin user
To check the powershell version :
$PSVersionTable
My custom firt action is write in ps1, remove registry value on installation
Remove-ItemProperty -Path HKLM:\SOFTWARE\Wow6432Node\Citrix\PNAgent -Name ServerURL -ErrorAction SilentlyContinue
and remove files and folders in the folder C:\Windonws\Logs\CBS during uninstallation.
Remove-Item "C:\Windows\Logs\CBS\" -Force -Recurse -ErrorAction SilentlyContinue
1)First set a System Search to check PowerShell is installed.
Signature |
Root |
Key |
Name |
Type |
Windows_PowerShell_sin |
2 |
SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine |
PowerShellVersion |
2 |
2)Next select the Policy execution for the Custom Action
Have to set the required property .
IS_PS_EXECUTIONPOLICY= Unrestricted|RemoteSigned|AllSigned
I choose Unrestricted because I have not signed my script.
Property |
Value |
IS_PS_EXECUTIONPOLICY |
Unrestricted |
3)After Add the PowerShell Custon Action
Action |
Type |
Source |
Target |
Extended |
sample_custom_action_ps1 |
1 |
ISPSWRAP.DLL |
PS1 |
|
4) In the Binary table add the script file
Name |
Data |
ISBuildSourcePath |
ISPSWRAP.DLL |
[Binary Data] |
<ISProductFolder>\redist\language independent\i386\PowerShellWrap.dll |
5) Eventually put the custom action in the sequence between the custom ISPowerShellStartup and ISPowerShellCleanup with the Condition :
POWERSHELLVERSION<>" " AND REMOVE="ALL"
6) At the end compile and run it !
For more informations, looking for PowerShell in the InstallShield Help Library.
Comments