PowerShell v1.0 doesn't have a -file argument. It does have a -command argument 
which I'm using. Through trial and error I've discovered that it also works by 
omitting -command (on the command line at least).

I typically setup my command line as follows (without the line breaks and 
additional spacing):

<commandLine>
"[POWERSHELLEXE]"
  -Version 1.0
  -NoProfile
  -Command $ep = Get-ExecutionPolicy ;
           Set-ExecutionPolicy RemoteSigned ;
           C:\InstallDir\SampleScript.ps1 ;
           Set-ExecutionPolicy $ep ;
           exit $error.Count
</commandLine>

This requires admin privileges which the installer already requires. In any 
case, my original example was a minimal example that could be used to reproduce 
the behavior (given an appropriate execution policy setting).

Here's another contrasting example:

<!-- Action Style 1 -->
<CustomAction Id="SetPSCmd"
              Property="PSCmd"
              Value="&quot;[POWERSHELLEXE]&quot; [#SampleScriptPS1]"
              Execute="immediate"
              Return="check"/>
<CustomAction Id="PSCmd"
              BinaryKey="WixCA"
              DllEntry="CAQuietExec"
              Execute="deferred"
              Return="check"/>

<!-- Action Style 2 -->
<CustomAction Id="PSCA"
              Property="POWERSHELLEXE"
              ExeCommand="[#SampleScriptPS1]"
              Execute="deferred"
              Return="check"/>

<InstallExecuteSequence>
  <!-- Action Style 1 -->
  <Custom Action="SetPSCmd" Before="PSCmd"/>
  <Custom Action="PSCmd" After="InstallFiles"/>
  <!-- Action Style 2 -->
  <Custom Action="PSCA" After="InstallFiles"/>
</InstallExecuteSequence>

Action style 1 is my original example which hangs. Action style 2 does the 
exact same thing but it shows a console window while the powershell script 
executes. I currently use action style 2 because it actually works. Action 
style 1 should have the same effect but omit the console window but instead it 
hangs. (In other words, I don't think the problem is with my command line as 
I've confirmed it works multiple ways, including a different style of custom 
action.)

Edwin G. Castro
Software Developer - Staff
Electronic Banking Services
Fiserv
Office: 503-746-0643
Fax: 503-617-0291
www.fiserv.com
Please consider the environment before printing this e-mail


> -----Original Message-----
> From: Andrew Lee [mailto:a...@solarflare.com]
> Sent: Monday, March 16, 2009 7:32 AM
> To: General discussion for Windows Installer XML toolset.
> Subject: Re: [WiX-users] Executing PowerShell Silently Hangs Install
>
> Castro, Edwin (Hillsboro) wrote:
> > I've seen many people report that they are running powershell custom
> actions successfully but I can't seem to find any examples of how they
> do it. My goal is to run powershell silently.
> > [...SNIP...]
> > When I run my installer I notice that the progress bar moves to about
> halfway then stops moving. I can see the powershell process in task
> manager but it is not using up any CPU. When I look at the log file
> (installer is still "running") I see the following as the last lines of
> the log:
> >
> > MSI (s) (B4:10) [11:33:19:092]: Executing op:
> ActionStart(Name=PSCmd,,)
> > MSI (s) (B4:10) [11:33:19:136]: Executing op:
> CustomActionSchedule(Action=PSCmd,ActionType=1025,Source=BinaryData,Tar
> get=CAQuietExec,CustomActionData="C:\Windows\System32\WindowsPowerShell
> \v1.0\powershell.exe" C:\InstallDir\SampleScript.ps1)
> >
> Looks to me as though your custom action is trying to run:
>     C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
> C:\InstallDir\SampleScript.ps1
>
> I think Powershell needs the "-File" argument to specify a script to
> run
> on the command line.  Try
>     C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -File
> C:\InstallDir\SampleScript.ps1
>
> Are you aware that Powershell doesn't support running scripts by
> default?  I'd suggest you open Powershell and type:
>    help about_signing
>    help Set-ExecutionPolicy
>
> Your installer would be relying on the user to have *manually* set
> their
> Powershell execution policy to something other than the default.
>
> Best regards,
>
>
> Andrew
>
> --
> Andrew Lee                  Solarflare Communications
> mailto:a...@solarflare.com  Block 2, Second floor, Westbrook Centre
> tel:+44-1223-518040 x5507   Milton Road, Cambridge, CB4 1YG, UK
> fax:+44-1223-464225         http://www.solarflare.com/
>
>
> -----------------------------------------------------------------------
> -------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly
> and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based
> development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
> _______________________________________________
> WiX-users mailing list
> WiX-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wix-users
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to