Skip to content

Instantly share code, notes, and snippets.

@turibbio
Last active August 4, 2017 18:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turibbio/35a3c18bc5455efa34a7 to your computer and use it in GitHub Desktop.
Save turibbio/35a3c18bc5455efa34a7 to your computer and use it in GitHub Desktop.
Write Log in multiple files with Powershell
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