From dc3c8041be47bd28618d1346ca24b933955ba20c Mon Sep 17 00:00:00 2001 From: Sam Erde <20478745+SamErde@users.noreply.github.com> Date: Wed, 6 May 2026 05:15:21 -0400 Subject: [PATCH] fix: add Targets/OutputPath params and use Join-Path in New-OutputPath - Declare Targets and OutputPath as mandatory parameters instead of relying on ambient scope variables. - Replace string concatenation with Join-Path for cross-platform correctness and readability. - Add ShouldProcess guard so -WhatIf and -Confirm behave correctly. - Mirror same fix in the generated monolithic Invoke-Locksmith.ps1. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Invoke-Locksmith.ps1 | 21 ++++++++++++++------- Private/New-OutputPath.ps1 | 21 ++++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Invoke-Locksmith.ps1 b/Invoke-Locksmith.ps1 index 9c2b6dbf..1584cc5f 100644 --- a/Invoke-Locksmith.ps1 +++ b/Invoke-Locksmith.ps1 @@ -3136,8 +3136,8 @@ function New-OutputPath { Creates output directories for each forest. .DESCRIPTION - This script creates one output directory per forest specified in the $Targets variable. - The output directories are created under the $OutputPath directory. + Creates one output directory per forest specified in the Targets parameter. + The output directories are created under the OutputPath directory. .PARAMETER Targets Specifies the forests for which output directories need to be created. @@ -3152,11 +3152,18 @@ function New-OutputPath { #> [CmdletBinding(SupportsShouldProcess)] - param () - # Create one output directory per forest - foreach ( $forest in $Targets ) { - $ForestPath = $OutputPath + "`\" + $forest - New-Item -Path $ForestPath -ItemType Directory -Force | Out-Null + param ( + [Parameter(Mandatory)] + [array]$Targets, + + [Parameter(Mandatory)] + [string]$OutputPath + ) + foreach ($forest in $Targets) { + $ForestPath = Join-Path -Path $OutputPath -ChildPath $forest + if ($PSCmdlet.ShouldProcess($ForestPath, 'Create directory')) { + New-Item -Path $ForestPath -ItemType Directory -Force | Out-Null + } } } diff --git a/Private/New-OutputPath.ps1 b/Private/New-OutputPath.ps1 index a7af30dd..46b39ed7 100644 --- a/Private/New-OutputPath.ps1 +++ b/Private/New-OutputPath.ps1 @@ -4,8 +4,8 @@ Creates output directories for each forest. .DESCRIPTION - This script creates one output directory per forest specified in the $Targets variable. - The output directories are created under the $OutputPath directory. + Creates one output directory per forest specified in the Targets parameter. + The output directories are created under the OutputPath directory. .PARAMETER Targets Specifies the forests for which output directories need to be created. @@ -20,10 +20,17 @@ #> [CmdletBinding(SupportsShouldProcess)] - param () - # Create one output directory per forest - foreach ( $forest in $Targets ) { - $ForestPath = $OutputPath + "`\" + $forest - New-Item -Path $ForestPath -ItemType Directory -Force | Out-Null + param ( + [Parameter(Mandatory)] + [array]$Targets, + + [Parameter(Mandatory)] + [string]$OutputPath + ) + foreach ($forest in $Targets) { + $ForestPath = Join-Path -Path $OutputPath -ChildPath $forest + if ($PSCmdlet.ShouldProcess($ForestPath, 'Create directory')) { + New-Item -Path $ForestPath -ItemType Directory -Force | Out-Null + } } }