Private/Set-WorkspacePath.ps1
|
<#
.SYNOPSIS Sets and stores the workspace path .DESCRIPTION Saves the workspace path to module settings .PARAMETER WorkspacePath Path to the workspace folder #> function Set-WorkspacePath { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$WorkspacePath ) try { # Validate path does not contain sandbox or test directories if ($WorkspacePath -match '\\sandbox\\|\\test-|\\sandbox$|\\test$') { throw "Workspace path cannot contain 'sandbox' or 'test' directories. Sandbox paths are not allowed for production workspaces." } # Validate path if (-not (Test-Path -Path $WorkspacePath)) { throw "Workspace path does not exist: $WorkspacePath" } # Set module variable $script:NLBaselineWorkspacePath = $WorkspacePath # Save to module settings $moduleDataPath = Join-Path -Path $env:LOCALAPPDATA -ChildPath "NLBaseline" if (-not (Test-Path -Path $moduleDataPath)) { New-Item -ItemType Directory -Path $moduleDataPath -Force | Out-Null } $settingsPath = Join-Path -Path $moduleDataPath -ChildPath "settings.json" $settings = @{ WorkspacePath = $WorkspacePath LastUpdated = (Get-Date -Format "yyyy-MM-dd HH:mm:ss") } $settings | ConvertTo-Json | Set-Content -Path $settingsPath -Force Write-Verbose "Workspace path saved: $WorkspacePath" return $true } catch { Write-Error "Failed to set workspace path: $_" return $false } } |