JSON to Registry

Aus Wiki-WebPerfect
Version vom 16. Oktober 2020, 12:54 Uhr von Admin (Diskussion | Beiträge)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

This PowerShell function can write recursively Registry-Keys based on a JSON-Object even this JSON is nested (JSON-tree to Registry-tree). -> This function/script is moved to GitHub!


For example you have the following JSON-Object:

$JSON = '{
    "Key1" : "Value1",
    "Key2" : "Value2",
    "KeywithSubKeys": {
        "SubKey1" : "SubValue1",
        "SubKey2" : "SubValue2",
        "SubKeywithArray" : ["ArrayValue1", "ArrayValue2"]
    },
    "Key3" : 1
}'

First convert this JSON to an custom PowerShell-Object:

$JSON = $JSON | ConvertFrom-Json

Now you can use the Write-JsonToRegistry function to write this to your Registry. For example I want to write the JSON-Tree to "HKEY_CURRENT_USER\SOFTWARE\RHE":

Write-JsonToRegistry -InputObject $JSON -RegistryPath "HKCU:\SOFTWARE\RHE"