PDA

View Full Version : How to debug a PowerShell script in a CA



sschantz
01-27-2015, 09:11 AM
Hi,
I am creating a Basic MSI project with InstallShield 2014. I am using a CA that will execute a PowerShell script to install IIS on a Server 2008 R2 (64 bit).
When I run the script manually in the PowerShell windows, IIS is installed correctly.
When it is run from the installer nothing is installed.
The log of the MSI show no errors


MSI (c) (B0:70) [08:00:07:689]: Doing action: CA_Install_IIS_Power
Action 8:00:07: CA_Install_IIS_Power.
Action start 8:00:07: CA_Install_IIS_Power.
MSI (c) (B0:4C) [08:00:07:692]: Invoking remote custom action. DLL: C:\Users\ADMINI~1\AppData\Local\Temp\2\MSIE1FE.tmp, Entrypoint: PS1
InstallShield 8:00:07: Beginning Run PowerShell...
InstallShield 8:00:15: Finished Run PowerShell
Action ended 8:00:15: CA_Install_IIS_Power. Return value 1

I have followed the steps described here http://helpnet.flexerasoftware.com/installshield19helplib/helplibrary/CAPowerShell.htm
And set the IS_PS_EXECUTIONPOLICY property to Unrestricted The script is stored in the binary table

How can I debug a PS running from a CA?

Here is the script

# Loading Feature Installation Modules
# --------------------------------------------------------------------
Import-Module ServerManager
# --------------------------------------------------------------------
# Installing IIS
# --------------------------------------------------------------------
Add-WindowsFeature -Name Web-Common-Http,Web-Asp-Net,Web-Net-Ext,Web-ISAPI-Ext,Web-ISAPI-Filter,Web-Http-Logging,Web-Request-Monitor,Web-Basic-Auth,Web-Windows-Auth,Web-Filtering,Web-Performance,Web-Mgmt-Console,Web-Mgmt-Compat,RSAT-Web-Server,WAS -IncludeAllSubFeature

Thank you

Sascha

MichaelU
01-27-2015, 09:36 AM
I'm not 100% sure, but I think our PowerShell support launches a 32-bit PowerShell engine. On the other hand, I'm pretty sure that modifying Windows Features requires the same bitness as the operating system, so would require a 64-bit PowerShell engine. Could you try explicitly invoking a 64-bit PowerShell engine, or check out the Windows Feature support in the Suite/Advanced UI project type?

sschantz
01-28-2015, 08:50 AM
I did create a Lunch EXE CA that run the following stored in the directory table.
I have created a directory path POWER_SHELL that is set to :C:\Windows\System32\WindowsPowerShell\v1.0
The command I execute is : powershell.exe -ExecutionPolicy RemoteSigned -file "[SUPPORTDIR]\InstallIIS.ps1"

Still this is not installing the IIS and no error is logged in the MSI log file.


MSI (c) (BC:E8) [08:29:23:073]: Doing action: CA_Install_IIS_Power_EXE
Action 8:29:23: CA_Install_IIS_Power_EXE.
Action start 8:29:23: CA_Install_IIS_Power_EXE.
Action ended 8:29:31: CA_Install_IIS_Power_EXE. Return value 1.

Is this the proper way to call powershell?



Thank you

Sascha

MichaelU
01-28-2015, 11:03 AM
I'm no PowerShell expert, but that looks reasonable on the surface. Except for one thing: if your package is a 32-bit package, this will be redirected to launch C:\Windows\SysWow64\WindowsPowerShell\v1.0\powershell.exe instead of the System32 path. That is, it will still run a 32-bit PowerShell.

sschantz
01-28-2015, 03:12 PM
So then, how do I force a 32-bit package to call the 64 bit version of a OS command?

DLee65
01-29-2015, 02:38 PM
My guess is that you may be running into a path substitution issue.

Looking at my VMWare image of Windows 7x64 I see that the x86 version uses the following path:

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe

x64 uses the System path you specified in your previous post. I wonder if the installer is seeing that you are a 32bit app and so does substitution to the path above? I am not sure of what the right answer is here, but, if this IS the case, then I would create a custom InstallScript action that sets a new directory path to the one you desire. InstallScript has the ability to specify "REGDB_OPTIONS = REGDB_OPTIONS | REGDB_OPTION_WOW64_64KEY;"

I used this approach to determine if our database instance exists in a x86 or x64 version of SQL Server.

For more information open help and look at the section for "Targeting 64-Bit Operating Systems with InstallScript Installations". There is a constant 'WOW64FSREDIRECTION' that can be used with the Disable and Enable to disable the file system reflection.

Again, this is ONLY a guess on my part based on what I am reading as to what might be going on. Hopefully it helps to find a solution.

sschantz
01-30-2015, 08:42 AM
Hi,

I have found a way to get the PowerShell script to be run from a CA.

Following Lee suggestion, I have created a InstallScript CustomAction that will call an InstallScript function.
Here is a snippet of the IS Function:


sCommand = "-ExecutionPolicy RemoteSigned -file \""+p_sPowerScriptFile+"\"";
Disable(WOW64FSREDIRECTION);
nResult = LaunchAppAndWait (WINSYSDIR64^"WindowsPowerShell\\v1.0\\powershell.exe", sCommand, LAAW_OPTION_WAIT | LAAW_OPTION_USE_SHELLEXECUTE);
Enable(WOW64FSREDIRECTION);

Now the PowerShell script gets executed with no error.

Thank you all for your input.

Sascha