Private/Start-QuickStart.ps1
|
function Start-QuickStart { <# .SYNOPSIS Quick Start configuration wizard .DESCRIPTION Configures the storage path and creates config.json template #> [CmdletBinding()] param() if ($Host.UI.RawUI) { try { Clear-Host } catch { Write-Host "`n`n`n" } } Write-Host "========================================" -ForegroundColor Cyan Write-Host " QUICK START CONFIGURATION" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # Get or set storage path $moduleConfigPath = Get-ConfigPath $moduleConfig = @{} if (Test-Path $moduleConfigPath) { $moduleConfig = Get-Content $moduleConfigPath | ConvertFrom-Json Write-Host "Current storage path: $($moduleConfig.StoragePath)" -ForegroundColor Gray } Write-Host "Enter the path where policies and configuration will be stored:" -ForegroundColor Yellow $storagePath = Read-Host "Storage Path" if ([string]::IsNullOrWhiteSpace($storagePath)) { Write-Error "Storage path is required" return } # Create storage directory if it doesn't exist if (-not (Test-Path $storagePath)) { try { New-Item -Path $storagePath -ItemType Directory -Force | Out-Null Write-Host "Storage directory created: $storagePath" -ForegroundColor Green } catch { Write-Error "Could not create storage directory: $_" return } } $moduleConfig.StoragePath = $storagePath # Create config.json template in storage path $configPath = Join-Path $storagePath "config.json" # Check if config.json already exists if (Test-Path $configPath) { Write-Host "" Write-Host "Configuration file already exists: $configPath" -ForegroundColor Yellow Write-Host "Do you want to overwrite it? (Y/N)" -ForegroundColor White $overwrite = Read-Host if ($overwrite -ne "Y" -and $overwrite -ne "y") { Write-Host "Keeping existing configuration file." -ForegroundColor Gray $moduleConfig | ConvertTo-Json | Out-File -FilePath $moduleConfigPath -Encoding UTF8 Write-Host "" Write-Host "Configuration path: $configPath" -ForegroundColor Cyan return } } # Create config.json template with placeholder values $config = @{ TenantId = "" ClientId = "" ClientSecret = "" OpenAIEndpoint = "" OpenAIApiKey = "" OpenAIModel = "gpt-4o" LastSaved = (Get-Date).ToString("o") } # Save config.json in storage path $config | ConvertTo-Json | Out-File -FilePath $configPath -Encoding UTF8 Write-Host "" Write-Host "Configuration template created: $configPath" -ForegroundColor Green Write-Host "" # Save main module configuration $moduleConfig | ConvertTo-Json | Out-File -FilePath $moduleConfigPath -Encoding UTF8 # Create Baseline folder and copy policies from module $baselinePath = Join-Path $storagePath "Baseline" if (-not (Test-Path $baselinePath)) { Write-Host "" Write-Host "Creating Baseline folder..." -ForegroundColor Yellow New-Item -Path $baselinePath -ItemType Directory -Force | Out-Null # Copy baseline policies from module # Get module root - this function is in Private folder, so go up two levels $moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) $moduleBaselinePath = Join-Path $moduleRoot "NLBaselineCA\Baseline" if (Test-Path $moduleBaselinePath) { $modulePolicyFiles = Get-ChildItem -Path $moduleBaselinePath -Filter "*.json" -File -ErrorAction SilentlyContinue if ($modulePolicyFiles -and $modulePolicyFiles.Count -gt 0) { Write-Host "Copying $($modulePolicyFiles.Count) baseline policies from module..." -ForegroundColor Yellow foreach ($file in $modulePolicyFiles) { $destPath = Join-Path $baselinePath $file.Name Copy-Item -Path $file.FullName -Destination $destPath -Force } Write-Host "Baseline folder created with $($modulePolicyFiles.Count) policies." -ForegroundColor Green } } } else { # Check if Baseline folder is empty and fill it if needed $existingPolicies = Get-ChildItem -Path $baselinePath -Filter "*.json" -File -ErrorAction SilentlyContinue if (-not $existingPolicies -or $existingPolicies.Count -eq 0) { Write-Host "" Write-Host "Baseline folder exists but is empty. Copying baseline policies from module..." -ForegroundColor Yellow $moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) $moduleBaselinePath = Join-Path $moduleRoot "NLBaselineCA\Baseline" if (Test-Path $moduleBaselinePath) { $modulePolicyFiles = Get-ChildItem -Path $moduleBaselinePath -Filter "*.json" -File -ErrorAction SilentlyContinue if ($modulePolicyFiles -and $modulePolicyFiles.Count -gt 0) { foreach ($file in $modulePolicyFiles) { $destPath = Join-Path $baselinePath $file.Name Copy-Item -Path $file.FullName -Destination $destPath -Force } Write-Host "Baseline folder populated with $($modulePolicyFiles.Count) policies." -ForegroundColor Green } } } } Write-Host "" Write-Host "========================================" -ForegroundColor Cyan Write-Host " NEXT STEPS" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" Write-Host "1. Open the configuration file:" -ForegroundColor Yellow Write-Host " $configPath" -ForegroundColor Cyan Write-Host "" Write-Host "2. Fill in the following values:" -ForegroundColor Yellow Write-Host " - TenantId: Your Azure AD Tenant ID" -ForegroundColor White Write-Host " - ClientId: Your App Registration (Application) ID" -ForegroundColor White Write-Host " - ClientSecret: Your App Registration Client Secret" -ForegroundColor White Write-Host " - OpenAIEndpoint: (Optional) Your OpenAI/Azure OpenAI endpoint" -ForegroundColor White Write-Host " - OpenAIApiKey: (Optional) Your OpenAI API key" -ForegroundColor White Write-Host " - OpenAIModel: (Optional) Model name, e.g. gpt-4o-mini" -ForegroundColor White Write-Host "" Write-Host "3. Save the file and return to the menu" -ForegroundColor Yellow Write-Host "" Write-Host "Example config.json structure:" -ForegroundColor Gray Write-Host @" { "TenantId": "your-tenant-id-here", "ClientId": "your-app-id-here", "ClientSecret": "your-client-secret-here", "OpenAIEndpoint": "https://your-endpoint.openai.azure.com/", "OpenAIApiKey": "your-api-key-here", "OpenAIModel": "gpt-4o-mini", "LastSaved": "$((Get-Date).ToString("o"))" } "@ -ForegroundColor DarkGray Write-Host "" Write-Host "Storage Path: $storagePath" -ForegroundColor Gray Write-Host "Config File: $configPath" -ForegroundColor Gray Write-Host "Baseline Path: $baselinePath" -ForegroundColor Gray } |