-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ScriptConfig.ps1
More file actions
59 lines (49 loc) · 1.84 KB
/
Copy pathGet-ScriptConfig.ps1
File metadata and controls
59 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<#
.SYNOPSIS
Load configuration for PowerShell scripts.
.DESCRIPTION
Loads configuration from config.json in the scripts directory.
If config.json doesn't exist, prompts to create from example.
.EXAMPLE
$config = Get-ScriptConfig
$config.ssh.servers
#>
[CmdletBinding()]
param()
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$configPath = Join-Path $scriptDir "config.json"
$examplePath = Join-Path $scriptDir "config.example.json"
# Check if config exists
if (-not (Test-Path $configPath)) {
Write-Host ""
Write-Host "Configuration file not found!" -ForegroundColor Yellow
Write-Host ""
Write-Host "To set up your configuration:" -ForegroundColor Cyan
Write-Host " 1. Copy config.example.json to config.json" -ForegroundColor White
Write-Host " 2. Edit config.json with your settings" -ForegroundColor White
Write-Host ""
if (Test-Path $examplePath) {
Write-Host "Would you like to create config.json from the example now? (Y/N): " -NoNewline -ForegroundColor Yellow
$response = Read-Host
if ($response -eq 'Y' -or $response -eq 'y') {
Copy-Item $examplePath $configPath
Write-Host ""
Write-Host "Created config.json - please edit it with your settings." -ForegroundColor Green
Write-Host "Location: $configPath" -ForegroundColor Gray
Write-Host ""
# Open in editor if available
if (Get-Command notepad -ErrorAction SilentlyContinue) {
Start-Process notepad $configPath
}
}
}
return $null
}
# Load and parse config
try {
$config = Get-Content $configPath -Raw | ConvertFrom-Json
return $config
} catch {
Write-Host "Error loading config.json: $($_.Exception.Message)" -ForegroundColor Red
return $null
}