How to create new clone instance of PSObject object

前端 未结 9 693
野趣味
野趣味 2020-12-09 02:20

I want to create new instance of my custom PSObject. I have a Button object created as PSObject and I want to create new object Button2 which has the same members as Button

9条回答
  •  借酒劲吻你
    2020-12-09 03:07

    The Better way i found out was to use ConvertTo-Json and ConvertFrom-Json. Ee - Suppose you want to clone a object $toBeClonedObject, just run below code to clone.

    $clonedObject = $toBeClonedObject | ConvertTo-Json | ConvertFrom-Json
    

提交回复
热议问题