“Powershell konvertieren zu JSON” Code-Antworten

Powershell konvertieren zu JSON

You could try some string manipulation to get it in an expected JSON format, and then use ConvertFrom-Json to convert it to a PSCustomObject.

Simple Example: (simple because this assumes that these characters being replaced will only be delimiters)

# First, clean up the string.
PS C:\> $mystring = "@{Account='User01';Domain='Domain01';Admin='True'}"
PS C:\> $mystring = $mystring -replace "^@", ""
PS C:\> $mystring = $mystring -replace "=", ":"
PS C:\> $mystring = $mystring -replace ";", ","
PS C:\> $mystring
{Account:'User01',Domain:'Domain01',Admin:'True'}

# Afterwards, convert to PSCustomObject.
PS C:\> $myobject = $mystring | ConvertFrom-Json
PS C:\> $myobject

Account                                 Domain                                  Admin
-------                                 ------                                  -----
User01                                  Domain01                                True
Ankur

Wie man in Powershell zu JSON zurückkehrt

ConvertTo-Json -InputObject $my_object
Defiant Dog

Ähnliche Antworten wie “Powershell konvertieren zu JSON”

Fragen ähnlich wie “Powershell konvertieren zu JSON”

Weitere verwandte Antworten zu “Powershell konvertieren zu JSON” auf Shell/Bash

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen