Update TGBeta.ps1
This commit is contained in:
36
TGBeta.ps1
36
TGBeta.ps1
@@ -13,16 +13,24 @@
|
||||
### need to move the tweaks to the tweeks tab
|
||||
|
||||
|
||||
#region Write-Log
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 1) CREATE A GLOBAL LOG CACHE (NEW)
|
||||
# ---------------------------------------------------------------------------
|
||||
# - Global log cache stores logs for session-wide accessibility.
|
||||
# - Logs are stored in a [System.Collections.ArrayList] for easy JSON conversion.
|
||||
# - Ensure log cache integrity during session restarts.
|
||||
if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) {
|
||||
$Global:LogCache = New-Object System.Collections.ArrayList
|
||||
}
|
||||
|
||||
|
||||
# Check if the Write-Log function exists
|
||||
#region Write-LogHelper
|
||||
# ---------------------------------------------------------------------------
|
||||
# 2) DEFINE THE Write-LogHelper FUNCTION
|
||||
# ---------------------------------------------------------------------------
|
||||
# - Write-LogHelper manages logging with customizable levels, task categories, and optional event logging.
|
||||
# - Supported log levels: Info, Warning, Error, Success, General.
|
||||
# - Task categories should match high-level operations (e.g., "On-boarding", "Off-boarding").
|
||||
if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction SilentlyContinue)) {
|
||||
# If the Write-Log function doesn't exist, create the Write-LogHelper function
|
||||
function Write-LogHelper {
|
||||
@@ -37,7 +45,7 @@ if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction Silentl
|
||||
[int]$CustomEventID # Optional custom Event ID
|
||||
)
|
||||
|
||||
# Simplified Event ID mapping
|
||||
# Simplified Event ID mapping for consistent logging
|
||||
$EventID = switch ($Level) {
|
||||
"Info" { 1000 }
|
||||
"Warning" { 2000 }
|
||||
@@ -55,7 +63,7 @@ if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction Silentl
|
||||
"General" { ([char]0x1F4E6) } # Package icon
|
||||
}
|
||||
|
||||
# Map levels to colors
|
||||
# Map levels to colors for console output
|
||||
$Color = switch ($Level) {
|
||||
"Info" { "Cyan" }
|
||||
"Warning" { "Yellow" }
|
||||
@@ -68,8 +76,9 @@ if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction Silentl
|
||||
# Write-Host "$Icon [$Level] [$TaskCategory] $Message (Event ID: $EventID)" -ForegroundColor $Color
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# 2) ALSO STORE THE LOG IN OUR GLOBAL LOG CACHE (NEW)
|
||||
# 3) STORE LOGS IN GLOBAL CACHE
|
||||
# -------------------------------------------------------------------
|
||||
# - Cache format: Timestamp, Level, and Message for each log entry.
|
||||
$logEntry = [PSCustomObject]@{
|
||||
Timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")
|
||||
Level = $Level
|
||||
@@ -77,8 +86,11 @@ if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction Silentl
|
||||
}
|
||||
[void]$Global:LogCache.Add($logEntry)
|
||||
# -------------------------------------------------------------------
|
||||
### TODO: Add support for exporting logs to a persistent file.
|
||||
# Consider implementing a periodic export mechanism to save logs to a file.
|
||||
# Example: Export-LogCacheToFile -Path "C:\Logs\TaskLogs.json"
|
||||
|
||||
# Optionally log to the Windows Event Log
|
||||
# Optional: Log to Windows Event Log for system-wide visibility.
|
||||
if ($LogToEvent) {
|
||||
$EntryType = switch ($Level) {
|
||||
"Info" { "Information" }
|
||||
@@ -100,6 +112,8 @@ if (-not (Get-Command -Name Write-Log -CommandType Function -ErrorAction Silentl
|
||||
}
|
||||
}
|
||||
|
||||
### Hybrid Function:
|
||||
# Wrapper for Write-LogHelper to simplify usage across modules.
|
||||
function Write-LogHybrid {
|
||||
param (
|
||||
[string]$Message,
|
||||
@@ -138,10 +152,9 @@ else {
|
||||
# Example usage of Write-LogHybrid
|
||||
Write-LogHybrid -Message "Starting SVS TaskGate" -Level "Info" -TaskCategory "SVSTaskGate" -LogToEvent:$true
|
||||
#endregion
|
||||
|
||||
#region SVS Module
|
||||
|
||||
|
||||
|
||||
function Install-SVSMSP {
|
||||
param (
|
||||
# Cleanup flag
|
||||
@@ -199,10 +212,7 @@ function Install-SVSMSP {
|
||||
[Parameter(Mandatory = $false)]
|
||||
[string]$ApiSecretKey
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function Perform-Cleanup {
|
||||
Write-LogHybrid -Message "Cleanup mode enabled. Starting cleanup process..." -Level "Info" -LogToEvent
|
||||
|
||||
|
||||
Reference in New Issue
Block a user