Skip to content

Instantly share code, notes, and snippets.

@noahpeltier
Created April 22, 2019 21:57
Show Gist options
  • Save noahpeltier/970e66026d509b7ee002bf2539e07440 to your computer and use it in GitHub Desktop.
Save noahpeltier/970e66026d509b7ee002bf2539e07440 to your computer and use it in GitHub Desktop.
Will write contents to a log with a time stamp -Error switch for writing to a seperate log for errors if need
Function Write-Log() {
[CmdletBinding()]
Param(
[switch]$Error,
[string]$Message
)
if ($Error) {
$timestamp = (get-date -uformat "%Y%m%d-%H.%M.%S -").ToString()
Add-content -path $ErrorLog -Value "$timestamp : $Message"
}
Else {
$timestamp = (get-date -uformat "%Y%m%d-%H.%M.%S -").ToString()
Add-content -path $LogFile -Value "$timestamp : $Message"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment