PDA

View Full Version : PowerShell Method to Copy MSI Log at end of Install



DonAIR
09-14-2018, 08:58 AM
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:


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)

DanGalender
09-14-2018, 11:22 PM
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?

DonAIR
09-17-2018, 08:23 AM
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.

Roman1
09-18-2018, 08:03 AM
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-Write-To-Log

DonAIR
09-18-2018, 09:54 AM
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-Write-To-Log

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