I'm writing a powershell script, in it I want to create a powershell custom object from a json file using the ConvertFrom-Json cmdlet. I then want to be able to pass this object into a function. When I check the type of the object with Get-Member, it shows me:
TypeName: System.Management.Automation.PSCustomObject
I thus write my function with a parameter:
Function Do-Something()
{
param(
[parameter(mandatory=$true)]
[System.Management.Automation.PSCustomObject]$jsonObject
)
#do something with $jsonObject
}
But when I call the function, and pass in the $jsonObject, I get an error:
Do-Something : Cannot process argument transformation on parameter 'jsonObject'. Cannot convert the "@{Things=System.Object[]}" value of type "System.Management.Automation.PSCustomObject" to type "System.Management.Automation.PSCustomObejct".
I may resign to simply recreate the object each time the function is called, but thinking there is something more basic that will allow me to just create the object once and pass it around by reference. Help, please, and thanks.
[PSCustomObject]
instead. Or just leave it out, since there's not much value to it if you're passing generic JSON. – Jeroen Mostertpscustomobject
you can use[ValidateScript({ $_ -is [System.Management.Automation.PSCustomObject] })]
aside from that, your question is explained here stackoverflow.com/questions/49152776/… – Santiago Squarzon