Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell how to convert System.Collections.Generic.Dictionary to PSCustomObject?

Tags:

powershell

I have a System.Collections.Generic.Dictionary that I have obtained by running the code snippet below. How do I convert $Obj to a PSCustomObject?

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$jsonserial= New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
$jsonserial.MaxJsonLength  = 67108864
$Obj = $jsonserial.DeserializeObject($JsonString)
like image 835
Josh Petitt Avatar asked Mar 17 '23 17:03

Josh Petitt


1 Answers

New-Object should work from PS 2.0 onwards:

$custom = new-object PSCustomObject -Property $obj
like image 172
Mike Zboray Avatar answered Apr 26 '23 14:04

Mike Zboray