JSON is a human-readable serialization format for storing structured automation data. It supports key-value pairs, strings, numbers, dates, Boolean values, arrays, and nested objects, making it a practical default when no specific requirement favors another format. section 6.2.2
Use JSON to separate automation data from PowerShell logic:
- Build a PowerShell object from a defined structure, then convert it to a JSON string with ConvertTo-Json. section 6.2.2
- Convert JSON text back into a PowerShell object with ConvertFrom-Json. section 6.2.2
- Combine the string-based JSON cmdlets with Out-File and Get-Content for local files, or supply strings from web requests, SQL databases, or parameters. section 6.2.2
- Store data files alongside directly related scripts and use them to drive reusable functions and script execution. section 6.4
Configuration-driven registry checks
Represent each check as an object containing a registry KeyPath, a Name, and Tests with an operator and value. Serialize the collection to JSON, save it, then reload it and let the script execute the checks from configuration rather than repeated hard-coded logic. section 6.2.2 section 6.4
Listing 6.4 Creating JSON
[System.Collections.Generic.List[PSObject]] $JsonBuilder = @()
$JsonBuilder.Add(@{ #1
KeyPath =
'HKLM:\SYSTEM\CurrentControlSet\Services\LanManServer\Parameters'
Name = 'EnableSecuritySignature'
Tests = @(
@{operator = 'eq'; value = '1' }
)
})
$JsonBuilder.Add(@{
KeyPath =
'HKLM:\SYSTEM\CurrentControlSet\Services\EventLog\Security'
Name = 'MaxSize'
Tests = @(
@{operator = 'ge'; value = '32768' }
)
})
$JsonBuilder.Add(@{
KeyPath =
'HKLM:\SYSTEM\CurrentControlSet\Services\LanManServer\Parameters'
Name = 'AutoDisconnect'
Tests = @(
@{operator = 'in'; value = '1..15' }
)
})
$JsonBuilder.Add(@{
KeyPath =
'HKLM:\SYSTEM\CurrentControlSet\Services\LanManServer\Parameters'
Name = 'EnableForcedLogoff'
Tests = @(
@{operator = 'eq'; value = '1' }
@{operator = 'eq'; value = '$null' }
)
})
$JsonBuilder | #2
ConvertTo-Json -Depth 3 |
Out-File .\RegistryChecks.json -Encoding UTF8
Inspect the PowerShell construction of a JSON-ready collection containing registry paths, property names, operators, and expected values. section 6.2.2


































