From 1a7f77bbb98910d86904271f3ca7f47e4042bd48 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Mon, 7 Jul 2025 21:05:35 -0400 Subject: [PATCH] Update StackMonkey_v1.ps1 --- StackMonkey_v1.ps1 | 54 ++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/StackMonkey_v1.ps1 b/StackMonkey_v1.ps1 index f619967..42a0423 100644 --- a/StackMonkey_v1.ps1 +++ b/StackMonkey_v1.ps1 @@ -293,7 +293,8 @@ [Parameter(Mandatory)][string]$Message, [ValidateSet("Info","Warning","Error","Success","General")][string]$Level = "Info", [string]$TaskCategory = "GeneralTask", - [switch]$LogToEvent, [string]$EventSource="SVSMSP_Module", [string]$EventLog="Application", + [switch]$LogToEvent, [string]$EventSource="SVSMSP_Module", [string]$EventLog = "SVS Scripting", +, [int]$CustomEventID, [string]$LogFile, [switch]$PassThru ) # IDs & colors @@ -333,25 +334,40 @@ # ───────────────────────────────────────────────────────────────────────── # WRITE-LOG HYBRID (single definition, chooses at runtime) # ───────────────────────────────────────────────────────────────────────── - function Write-LogHybrid { - [CmdletBinding()] - param( - [Parameter(Mandatory=$true)][string]$Message, - [ValidateSet("Info","Warning","Error","Success","General")] - [string]$Level = "Info", - [string]$TaskCategory = "GeneralTask", - [switch]$LogToEvent - ) + function Write-LogHybrid { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)][string]$Message, + [ValidateSet("Info","Warning","Error","Success","General")] + [string]$Level = "Info", + [string]$TaskCategory = "GeneralTask", + [switch]$LogToEvent, + [string]$EventSource = "Script Automation Monkey", + [string]$EventLog = "SVS Scripting" + ) + + if (Get-Command -Name Write-Log -ErrorAction SilentlyContinue) { + # SVSMSP module's Write-Log is available + Write-Log ` + -Message $Message ` + -Level $Level ` + -TaskCategory $TaskCategory ` + -LogToEvent:$LogToEvent ` + -EventSource $EventSource ` + -EventLog $EventLog + } + else { + # Fall back to your helper + Write-LogHelper ` + -Message $Message ` + -Level $Level ` + -TaskCategory $TaskCategory ` + -LogToEvent:$LogToEvent ` + -EventSource $EventSource ` + -EventLog $EventLog + } +} - if ( Get-Command -Name Write-Log -ErrorAction SilentlyContinue ) { - # SVSMSP module's Write-Log is available - Write-Log -Message $Message -Level $Level -TaskCategory $TaskCategory -LogToEvent:$LogToEvent - } - else { - # fall back to your helper - Write-LogHelper -Message $Message -Level $Level -TaskCategory $TaskCategory -LogToEvent:$LogToEvent - } - } #region Config & Task Definitions