cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Occasional contributor

PowerShell Method to Copy MSI Log at end of Install

I spent way to long trying to figure this out, so I figured I would share if anyone is looking to do the same. Most of the methods I found didn't work, or for some reason just wouldn't copy it (InstallScript etc).

PowerShell Custom Action Settings:

Run 64-bit PowerShell script: Yes
Return Processing: Synchronous (check exit code)
In-Script Execution: Immediate Execution (Terminal Server Aware)
Install Exec Sequence: After ISSearchReplaceFinalize


PowerShell Code:
[CODE]
trace-info -LogMessage "Running PS-CopyMSILog.ps1 Custom Action"

##########################################
# Set Variables
##########################################

$installdir = get-property -name INSTALLDIR
trace-info -LogMessage "installdir set to $installdir"
$msilogfile = get-property -name MsiLogFileLocation
trace-info -LogMessage "msilogfile set to $msilogfile"
$productversion = get-property -name ProductVersion
trace-info -LogMessage "productversion set to $productversion"

##########################################
# Get Date-Time
##########################################

$now = Get-Date -format "MM.dd.yyyy hh-mmtt"

##########################################
# Clear $Error
##########################################

$Error.Clear()

##########################################
# Copy Log File
##########################################

try
{
Copy-Item -Path "$msilogfile" -Destination "$installdir\Logs\Product v$productversion - $now.log" -Force -ErrorAction Stop
}
catch
{
$ErrorMessage = $Error[0].Exception.Message
trace-info -LogMessage "$msilogfile copy failed with exception $ErrorMessage"
exit(0)
}
trace-info -LogMessage "$msilogfile copied successfully to $installdir\Logs\Product v$productversion - $now.log"

exit(0)
[/CODE]
Labels (1)
4 Replies
Highlighted
Active participant

Re: PowerShell Method to Copy MSI Log at end of Install

If I understand correctly, you're trying to copy the MSI log file in a Custom Action? If the Custom Action is running, the log file will still be open until the installation terminates, which would prevent the Copy operation.

Am I missing something?
0 Kudos
Highlighted
Occasional contributor

Re: PowerShell Method to Copy MSI Log at end of Install

DanGalender wrote:
If I understand correctly, you're trying to copy the MSI log file in a Custom Action? If the Custom Action is running, the log file will still be open until the installation terminates, which would prevent the Copy operation.

Am I missing something?


Via InstallScript it fails for that reason (presumably), although I am not sure why a copy would fail, you can copy files that are open in windows, obviously a move I would expect to fail. That said, the above works fine with PowerShell, which is why I posted it.
0 Kudos
Highlighted
Flexera beginner

PS1 called by DoAction

PowerShell Custom Actions which are launched from a DoAction control event are unable to write to the MSI log.
This is documented in the below article:

PowerShell Trace-info Cmdlet Does Not Write To Log:

https://flexeracommunity.force.com/customer/articles/en_US/FAQ/PowerShell-Trace-info-Cmdlet-Does-Not...
0 Kudos
Highlighted
Occasional contributor

Re: PowerShell Method to Copy MSI Log at end of Install

Roman1 wrote:
PowerShell Custom Actions which are launched from a DoAction control event are unable to write to the MSI log.
This is documented in the below article:

PowerShell Trace-info Cmdlet Does Not Write To Log:

https://flexeracommunity.force.com/customer/articles/en_US/FAQ/PowerShell-Trace-info-Cmdlet-Does-Not...


Although true, this has nothing to do with the script I posted...
0 Kudos