Skip to content

Instantly share code, notes, and snippets.

@santisq
Created January 31, 2024 15:15
Show Gist options
  • Save santisq/2f17942d243957ebac22f36c7df17316 to your computer and use it in GitHub Desktop.
Save santisq/2f17942d243957ebac22f36c7df17316 to your computer and use it in GitHub Desktop.
$stream = [System.IO.MemoryStream]::new([System.Text.Encoding]::UTF8.GetBytes(@'
[
{
"DomainName": "example1.com",
"DomainNetBIOSName": "EXAMPLE1",
"IDRanges": [
{ "RangeStart": 2000, "RangeEnd": 2999, "Attribute": "uidNumber", "AccountType": "Computer" },
{ "RangeStart": 3000, "RangeEnd": 3999, "Attribute": "uidNumber", "AccountType": "MSA" },
{ "RangeStart": 4000, "RangeEnd": 4999, "Attribute": "gidNumber", "AccountType": "Group" },
{ "RangeStart": 5000, "RangeEnd": 5999, "Attribute": "uidNumber", "AccountType": "AdmAccount", "IDGeneration": { "Type": "Calculation", "RefDomain": null } },
{ "RangeStart": 6000, "RangeEnd": 6999, "Attribute": "gidNumber", "AccountType": "BuiltInGroup" }
]
},
{
"DomainName": "example2.com",
"DomainNetBIOSName": "EXAMPLE2",
"UIDGIDRanges": [
{ "RangeStart": 4000, "RangeEnd": 4999, "Attribute": "uidNumber", "AccountType": "Computer" },
{ "RangeStart": 5000, "RangeEnd": 5999, "Attribute": "uidNumber", "AccountType": "MSA" },
{ "RangeStart": 6000, "RangeEnd": 6999, "Attribute": "gidNumber", "AccountType": "Group" },
{ "RangeStart": 8000, "RangeEnd": 8999, "Attribute": "gidNumber", "AccountType": "BuiltInGroup" }
]
}
]
'@))
class AnObject {
[string] $DomainName
[string] $DomainNetBIOSName
[ordered[]] $UIDGIDRanges
[ordered[]] $IDRanges
}
$serializer = [Newtonsoft.Json.JsonSerializer]::new()
$reader = [System.IO.StreamReader] $stream
$jsonreader = [Newtonsoft.Json.JsonTextReader] $reader
while($jsonreader.Read()) {
if ($jsonreader.TokenType -eq [System.Text.Json.JsonTokenType]::StartObject) {
$serializer.Deserialize[AnObject]($jsonreader) | Format-List
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment