From e956a708f8187c06c00c9c79eca1469fea74eaeb Mon Sep 17 00:00:00 2001 From: "Stam, Marcel" <32320109+mstam13@users.noreply.github.com> Date: Wed, 9 Sep 2026 08:19:18 +0200 Subject: [PATCH] feat: Migrate logging to shared module and update log filename formats across multiple scripts --- Add-Named-Instances/Add-Named-Instances.ps1 | 9 +++++++-- CleanupPolicies/Cleanup-Policies.ps1 | 7 +++++-- Compare-GPOsByOU/Compare-GPOsByOU.ps1 | 6 +++++- Generate-RDCManConfigs/Generate-RDCManConfigs.ps1 | 6 +++++- Get-ServiceAccounts/Get-ServiceAccounts.ps1 | 3 ++- Shared/PublicScripts.psd1 | 2 +- Shared/PublicScripts.psm1 | 2 +- 7 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Add-Named-Instances/Add-Named-Instances.ps1 b/Add-Named-Instances/Add-Named-Instances.ps1 index 3ff7abd..2bbce9e 100644 --- a/Add-Named-Instances/Add-Named-Instances.ps1 +++ b/Add-Named-Instances/Add-Named-Instances.ps1 @@ -53,12 +53,17 @@ Writes log files to D:\Logs instead of the default C:\Temp. .NOTES Author : Marcel Stam - Date : 2026-05-21 - Version : 1.9.0 + Date : 2026-07-13 + Version : 2.0.0 Requires local administrator privileges. Intended for use as part of CIS SQL Server hardening. Version history: + 2.0.0 - 2026-07-13 - Migrated logging to shared module Shared\PublicScripts.psm1. + Removed local Write-Log and Remove-OldLogs function definitions; + script now uses shared Write-ScriptLog and Remove-OldLog. Log + filename format changed from Add-Named-Instances_yyyyMMdd_HHmmss.log + to yyyyMMdd_HHmmss_Add-Named-Instances.log. 1.0.0 - 2026-05-13 - Initial release. 1.1.0 - 2026-05-13 - Added explicit param() block; moved group name constants to dedicated Configuration region; added early exit when no instances diff --git a/CleanupPolicies/Cleanup-Policies.ps1 b/CleanupPolicies/Cleanup-Policies.ps1 index 330f641..da9e1b6 100644 --- a/CleanupPolicies/Cleanup-Policies.ps1 +++ b/CleanupPolicies/Cleanup-Policies.ps1 @@ -38,8 +38,8 @@ Runs against contoso.com and writes the report to C:\Reports. .NOTES Author : M. Stam - Date : 2026-06-25 - Version : 1.2.0 + Date : 2026-07-13 + Version : 1.3.0 Requires : GroupPolicy module (RSAT-GPMC) ActiveDirectory module (RSAT-AD-PowerShell) @@ -55,6 +55,9 @@ Group Policy' (Dutch: 'Groepsbeleid toepassen'), which caused false positives. Version history: + 1.3.0 2026-07-13 M. Stam Migrated logging to shared module Shared\PublicScripts.psm1. + Replaced Tee-Object log writer (produced UTF-8 BOM) with + Write-ScriptLog (UTF-8 without BOM). 1.2.0 2026-06-25 M. Stam Removed dead '-not $_.Denied' filter (GPPermission has no Denied property; GpoApply already implies Allow). 1.1.0 2026-06-25 M. Stam Fixed Apply ACE detection to use Get-GPPermission diff --git a/Compare-GPOsByOU/Compare-GPOsByOU.ps1 b/Compare-GPOsByOU/Compare-GPOsByOU.ps1 index bbf2230..01346d8 100644 --- a/Compare-GPOsByOU/Compare-GPOsByOU.ps1 +++ b/Compare-GPOsByOU/Compare-GPOsByOU.ps1 @@ -91,7 +91,7 @@ .NOTES Author : M. Stam Date : 2026-07-13 - Version : 1.4.0 + Version : 1.5.0 Requires : GroupPolicy module (RSAT-GPMC) ActiveDirectory module (RSAT-AD-PowerShell) @@ -110,6 +110,10 @@ root\CIMv2;SELECT * FROM Win32_OperatingSystem WHERE Version LIKE "10.%" Version history: + 1.5.0 2026-07-13 M. Stam Migrated logging to shared module Shared\PublicScripts.psm1. + Removed local Write-ScriptLog implementation and + $script:LogEncoding variable; these are now provided by + the module. 1.4.0 2026-07-13 M. Stam Optimised: parallel Get-GPInheritance on PS7+; elapsed-time logging per phase; UTF-8 NoBOM log writer; Dictionary + TryGetValue; diff --git a/Generate-RDCManConfigs/Generate-RDCManConfigs.ps1 b/Generate-RDCManConfigs/Generate-RDCManConfigs.ps1 index ace9b49..662bf6f 100644 --- a/Generate-RDCManConfigs/Generate-RDCManConfigs.ps1 +++ b/Generate-RDCManConfigs/Generate-RDCManConfigs.ps1 @@ -50,10 +50,14 @@ .NOTES Author: Joey Eckelbarger Editor: Marcel Stam - Version: 2.0.0 + Version: 2.1.0 Version History: 1.0.0 - Joey Eckelbarger - Initial release + 2.1.0 - Marcel Stam - 2026-07-13 + Migrated logging to shared module Shared\PublicScripts.psm1. + Log filename now includes the script name: + yyyyMMdd_HHmmss_Generate-RDCManConfigs.log. 2.0.0 - Marcel Stam - 2026-06-17 Added param block with ValidateScript Fixed: -Credential now passed to Get-ADComputer diff --git a/Get-ServiceAccounts/Get-ServiceAccounts.ps1 b/Get-ServiceAccounts/Get-ServiceAccounts.ps1 index 0d59f85..fa834d4 100644 --- a/Get-ServiceAccounts/Get-ServiceAccounts.ps1 +++ b/Get-ServiceAccounts/Get-ServiceAccounts.ps1 @@ -53,7 +53,8 @@ .NOTES Author : M. Stam - Date : 2026-06-10 + Date : 2026-07-13 + Version : 1.8 Requires: ActiveDirectory RSAT module, ImportExcel module, WMI/CIM access to target servers. PSRemoting (WinRM) is required for scheduled task enumeration; it is skipped gracefully when only DCOM is available. diff --git a/Shared/PublicScripts.psd1 b/Shared/PublicScripts.psd1 index c9f8163..5695853 100644 --- a/Shared/PublicScripts.psd1 +++ b/Shared/PublicScripts.psd1 @@ -2,7 +2,7 @@ ModuleVersion = '1.0.0' GUID = '03d050ae-a770-4d27-95a0-dbbb27602759' Author = 'M. Stam' - Description = 'Shared logging utilities (Initialize-ScriptLog, Write-ScriptLog, Remove-OldLogs) for PublicScripts repository scripts.' + Description = 'Shared logging utilities (Initialize-ScriptLog, Write-ScriptLog, Remove-OldLog) for PublicScripts repository scripts.' PowerShellVersion = '5.1' RootModule = 'PublicScripts.psm1' FunctionsToExport = @('Initialize-ScriptLog', 'Write-ScriptLog', 'Remove-OldLog') diff --git a/Shared/PublicScripts.psm1 b/Shared/PublicScripts.psm1 index b8893b7..8eb7d83 100644 --- a/Shared/PublicScripts.psm1 +++ b/Shared/PublicScripts.psm1 @@ -14,7 +14,7 @@ PowerShell stream (INFO -> Write-Information, WARN -> Write-Warning, ERROR -> Write-Error). All file output uses UTF-8 without BOM, compatible with PS 5.1 and PS 7+. - Remove-OldLogs Removes log files in a directory that are older than a configurable + Remove-OldLog Removes log files in a directory that are older than a configurable retention window. Supports -WhatIf / -Confirm. #>