Last active
August 1, 2023 16:18
-
-
Save dancing-groot/1d606c697959b0c80782d10811dbaec5 to your computer and use it in GitHub Desktop.
Provide visual feedback when running a script interactively
This file contains 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-Timestamp | |
{ | |
<# | |
.SYNOPSIS | |
Provide visual feedback when running a script interactively | |
.LINK | |
https://gist.github.com/dancing-groot/1d606c697959b0c80782d10811dbaec5 | |
.NOTES | |
Version: 2022.03.10 | |
Author: @dancing-groot | |
#> | |
[cmdletbinding()] | |
param ( | |
[string]$Message = "", | |
[ValidateSet('Warning', 'Error', 'Verbose', 'Debug', 'Information', 'Info')] | |
[string]$Type = "Info" | |
) | |
if ($Type -eq "Information") { $Type = "Info" } | |
$content = "$(Get-Date -UFormat '%Y.%m.%d %T')`t$Message" | |
switch ($Type) | |
{ | |
"Info" { Write-Information "INFO:`t$content" -InformationAction Continue; break } | |
"Warning" { Write-Warning "`t$content" -WarningAction Continue; break } | |
"Error" { $Host.Ui.WriteErrorLine("ERROR:`t$content"); break } | |
"Verbose" { $VerbosePreferenceBackup = $VerbosePreference; $VerbosePreference = "Continue"; Write-Verbose "`t$content"; $VerbosePreference = $VerbosePreferenceBackup; break } | |
"Debug" { $DebugPreferenceBackup = $DebugPreference; $DebugPreference = "Continue"; Write-Debug "`t$content"; $DebugPreference = $DebugPreferenceBackup; break } | |
} | |
} # Write-Timestamp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment