Both of the modules I posted can do that, though the second one is easier to use (requires fewer changes to your existing script):
# At beginning of script (either in the Begin block, if you're using begin/process/end, or just after the param() block) # This syntax assumes you've placed the PSLogging module in your modules directory. If not, you can specify an absolute # path to the folder or PSLogging.psd1 file instead of just 'PSLogging' in the Import-Module command. Import-Module PSLogging $logFile = Add-LogFile -Path C:\Path\To\LogFile.log # ... Your existing script code # At the end of the script $logFile | Disable-LogFile # Output should have been captured to the 'C:\Path\To\LogFile.log' file.