added way to add objects
This commit is contained in:
28
JSONfunctions.psm1
Normal file
28
JSONfunctions.psm1
Normal file
@@ -0,0 +1,28 @@
|
||||
function Get-ServerConfig {
|
||||
param(
|
||||
[string]$Path = ".\servers.json"
|
||||
)
|
||||
|
||||
if (-not (Test-Path $Path)) {
|
||||
throw "Config-Datei nicht gefunden: $Path"
|
||||
}
|
||||
|
||||
return Get-Content $Path -Raw | ConvertFrom-Json
|
||||
}
|
||||
|
||||
function Set-ServerConfig {
|
||||
param(
|
||||
[string]$Path = ".\servers.json",
|
||||
[string]$Name
|
||||
)
|
||||
|
||||
$servers = Get-ServerConfig -Path $Path
|
||||
|
||||
$server = $servers.groups.TST | Where-Object {$_.name -eq $Name}
|
||||
$server | Add-Member -MemberType NoteProperty -Name "role" -Value "web"
|
||||
|
||||
$servers | ConvertTo-Json -Depth 10 | Set-Content $Path
|
||||
|
||||
|
||||
return $server
|
||||
}
|
||||
Reference in New Issue
Block a user