From b51b7a133477d7e4c0ec0e666cf31cbcf2d38525 Mon Sep 17 00:00:00 2001 From: Leonardo Klein Date: Wed, 18 Feb 2026 18:31:12 -0300 Subject: [PATCH] fix: add undeclared LogPath and EnableDebugMode params to New-ShareAndDFS.ps1 These parameters were documented in the help block and README but missing from the param() block, causing runtime errors when used. Closes #1 --- Scripts/NetworkShares/New-ShareAndDFS.ps1 | 26 ++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Scripts/NetworkShares/New-ShareAndDFS.ps1 b/Scripts/NetworkShares/New-ShareAndDFS.ps1 index b306530..cf3a181 100644 --- a/Scripts/NetworkShares/New-ShareAndDFS.ps1 +++ b/Scripts/NetworkShares/New-ShareAndDFS.ps1 @@ -48,6 +48,7 @@ #> [CmdletBinding(SupportsShouldProcess)] +[System.Diagnostics.CodeAnalysis.SuppressMessage('PSReviewUnusedParameter', 'EnableDebugMode', Justification = 'Used in Write-ScriptLog function scope')] param ( [Parameter(Mandatory = $false)] [ValidateScript({ Test-Path $_ -PathType Container })] @@ -57,28 +58,47 @@ param ( [string]$DomainNamespace = "\\domain.local", [Parameter(Mandatory = $false)] - [string]$ServerName = $env:COMPUTERNAME + [string]$ServerName = $env:COMPUTERNAME, + + [Parameter(Mandatory = $false)] + [string]$LogPath = "C:\Logs", + + [Parameter(Mandatory = $false)] + [switch]$EnableDebugMode ) $ErrorActionPreference = 'Stop' +$script:LogFilePath = $null +if ($LogPath) { + if (-not (Test-Path $LogPath)) { + New-Item -Path $LogPath -ItemType Directory -Force | Out-Null + } + $timestamp = Get-Date -Format "yyyyMMdd_HHmmss" + $script:LogFilePath = Join-Path $LogPath "New-ShareAndDFS_${timestamp}.log" +} + function Write-ScriptLog { param( [string]$Message, [ValidateSet('Info', 'Warning', 'Error', 'Debug')] [string]$Level = 'Info' ) - + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $logMessage = "[$timestamp] [$Level] $Message" - + switch ($Level) { 'Info' { Write-Information $logMessage -InformationAction Continue } 'Warning' { Write-Warning $logMessage } 'Error' { Write-Error $logMessage } 'Debug' { if ($EnableDebugMode) { Write-Verbose $logMessage } } } + + if ($script:LogFilePath) { + $logMessage | Out-File -FilePath $script:LogFilePath -Append -Encoding UTF8 + } } function New-SMBShareSafe {