Avatar of eelou
eelou
 asked on

How to log a Powershell .ps1 file when executing custom action in InstallShield

InstallShield 2014 MSI installer.   Executing a custom Action.  The command below executes ok.  I am making some changes to the .ps1 file and now see some red\error text that scrolls quickly by, in the command window.

File name and command line: = C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe "& \"[INSTALLDIR]Data\ConfigWebsit.ps1\""

I am fairly new to PowerShell, I did not write the scripts that I am trying to modify.

I am trying to log the output (total output, not just a line or two in the file).  If I add the following, the execution of the script, and the install, fails...

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe "& \"[INSTALLDIR]Data\ConfigWebsit.ps1 > [INSTALLDIR]Configwebsit.ps1\""

This also fails...
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe "& \"[INSTALLDIR]Data\ConfigWebsit.ps1 > [INSTALLDIR]Configwebsit.ps1 | Out-File 'C:\path\to\your.log'\""

Can this be done?
PowershellInstallation

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
Qlemo

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe "& \"[INSTALLDIR]Data\ConfigWebsit.ps1\" > \"[INSTALLDIR]Configwebsit.log\""

Open in new window

should work, as does
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe "& '[INSTALLDIR]Data\ConfigWebsit.ps1' > '[INSTALLDIR]Configwebsit.log' "

Open in new window

and
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe "& '[INSTALLDIR]Data\ConfigWebsit.ps1' | Out-File '[INSTALLDIR]Configwebsit.log' "

Open in new window

eelou

ASKER
Making progress.  I used the first example, and did get a log file.  It does not though show the errors (that flashed by in red).  How can I get the errors, and\or both (good and bad)?
eelou

ASKER
I combined what I got from you, and some of what I found online (it appears to work)...

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe " & '[INSTALLDIR]Data\ConfigWebsit.ps1' 2>&1 | tee -filePath  '[INSTALLDIR]Configwebsit.log' "
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Qlemo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.