From 2f6e426048574ebf2f4453d3e6100f09d4abf25f Mon Sep 17 00:00:00 2001 From: Mindfang Date: Thu, 18 Jul 2024 13:43:05 -0500 Subject: [PATCH] Add LogTools --- HelperFunctions/LogTools.ps1 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 HelperFunctions/LogTools.ps1 diff --git a/HelperFunctions/LogTools.ps1 b/HelperFunctions/LogTools.ps1 new file mode 100644 index 0000000..6a68853 --- /dev/null +++ b/HelperFunctions/LogTools.ps1 @@ -0,0 +1,30 @@ +Function Add-LogEntry { + Param ( + [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()]$Message, + [Parameter(Mandatory = $false)] [ValidateSet('Notify', 'Warning', 'Error')]$As, + [Parameter(Mandatory = $false)] [Switch]$NewLine + ) + $Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + + Switch ($As) { + "Notify" { + $FGC = "Cyan" + } + "Warning" { + $FGC = "Yellow" + } + "Error" { + $FGC = "Red" + } + Default { + $FGC = "White" + } + } + + If ($Newline) { + Write-Host "`n[$Timestamp] $Message" -ForegroundColor $FGC + } + Else { + Write-Host "[$Timestamp] $Message" -ForegroundColor $FGC + } +} \ No newline at end of file