This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Re: PowerShell Method to Copy MSI Log at end of Install
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Sep 14, 2018
08:58 AM
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:
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]
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]
(4) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Sep 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?
Am I missing something?
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Sep 17, 2018
08:23 AM
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.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Sep 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
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
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Sep 18, 2018
09:54 AM
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-Write-To-Log
Although true, this has nothing to do with the script I posted...