Last active
August 4, 2017 18:00
-
-
Save turibbio/35a3c18bc5455efa34a7 to your computer and use it in GitHub Desktop.
Write Log in multiple files with Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Write-Messages | |
{ | |
[CmdletBinding()] | |
param( | |
[string]$warningFilePath = "C:\Temp\warning.txt", | |
[string]$errorFilePath = "C:\Temp\error.txt" | |
) | |
Write-Host "Host message" | |
Write-Output "Output message" | |
Write-Verbose "Verbose message" | |
Write-Warning "Warning message" 3>&1 | Tee-Object $warningFilePath | |
Write-Error "Error message" 2>&1 | Tee-Object $errorFilePath | |
Write-Debug "Debug message" | |
} | |
# Run with: | |
# Write-Messages *> C:\Temp\log.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment