JSON to Registry: Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „''This PowerShell function can write recursively Registry-Keys based on a JSON-Object even this JSON is nested (JSON-tree to Registry-tree).'' For example y…“)
 
Zeile 21: Zeile 21:
 
Now you can use the ''Write-JsonToRegistry'' function to write this to your Registry.
 
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":
 
For example I want to write the JSON-Tree to "HKEY_CURRENT_USER\SOFTWARE\RHE":
<source lang="powershell>Write-JsonToRegistry -InputObject $JSON -RegistryPath "HKCU:\SOFTWARE\RHE" </source>
+
<source lang="powershell">Write-JsonToRegistry -InputObject $JSON -RegistryPath "HKCU:\SOFTWARE\RHE" </source>
  
  

Version vom 16. Oktober 2020, 12:53 Uhr

This PowerShell function can write recursively Registry-Keys based on a JSON-Object even this JSON is nested (JSON-tree to Registry-tree).


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"