Topics for PowerShell's ConvertFrom-JSON
Introduction to ConvertFrom-JSON
PowerShell has a technique called Here-String for dealing with text; you need special care when handling text contain a lot of speech marks and other delimiters. Languages such as VBScript handle speech marks with escape characters, however, I find the resulting syntax cumbersome, and my first attempts usually contain hard-to-find errors. PowerShell handles this text data conversion easily, provided you master the Here-String construction. Here is a simple example:
Key point: Place @", and especially the final, "@ on their own line.
$Victim = $Input | ConvertFrom-JSON
Note 1: Observe the crucial @".."@ wrapper
# ConvertFrom-JSON output result:
FirstName LastName Email
Import users from a spreadsheet. Just provide a list of the users with their fields in the top row, and save as .csv file. Then launch this FREE utility and match your fields with AD's attributes, click and import the users.
Optionally, you can provide the name of the OU where the new accounts will be born. Download your FREE bulk import tool.
If you need more comprehensive application analysis software,
How did I know that: "The ConvertFrom-JSON cmdlet converts a JSON-formatted string to custom object (PSCustomObject) that has a property for each field in the JSON string"? The answer is that I interrogated the cmdlet with PowerShell's Get-Help thus:
Note 3: As is usual with Get-Help, the -Full parameter reveals examples of the cmdlet in action.
Remember the Difference Between @" and @'.
Be aware of the significance of @" and @'. PowerShell consistently treats the single quote as meaning literal, don't convert, whereas double quotes cause PowerShell to process variables as necessary. Here is a suitable vehicle to see the difference:
# Problem: single quote.
One is "$(1*1)"
Swap @" and "@ for @' and '@
## Result: Variable substitution inside @"...."@
Pay attention to sequencing. Start with @" (and not "@); finish with "@ (and not @").
Employ the correct type of quotes. Make sure that the text block itself employs only straight single or double quotes, not the curly variants. These alternatives, which I don't advise, precede quotation mark with the word left or right: For example &rsquo or Alt+0146; (right single quotation mark ’ ).
Research More ConvertFrom Cmdlets
The last cmdlet ConvertFrom-StringData surprised me; further research revealed that it also uses the here-string construction @'...'@.
Summary of PowerShell's ConvertFrom-JSON Cmdlet
If you like this page then please share it with your friends
See more Microsoft PowerShell output tutorials:
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.