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?
eelouAsked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
tee-object is used to send output to both a variable or file and down the pipe (usually going into further processing or dumping as console output). You better want to use
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe "& \"[INSTALLDIR]Data\ConfigWebsit.ps1\" 2>&1 > \"[INSTALLDIR]Configwebsit.log\""

Open in new window

0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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

0
 
eelouAuthor Commented:
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)?
0
 
eelouAuthor Commented:
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' "
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.