PowerTip: The Easy Way to Create a Custom PowerShell Object

PowerTip: The Easy Way to Create a Custom PowerShell Object

  • Comments 1
  • Likes

Summary: Create a custom Windows PowerShell object with the PSCustomObject type accelerator.

Hey, Scripting Guy! Question What’s the easiest way to create a custom object?

Hey, Scripting Guy! Answer Charlotte Windows PowerShell User group member Brian Wilhite says: One of the easiest ways to create a custom object is to use the PSCustomObject type accelerator.  This “shortcut” will not only create the custom object, but it will arrange the key/value pairs in the order in which they were entered.

$CustomObject = [PSCustomObject]@{a=1;c=3;b=2;d=4}

$CustomObject | Get-Member

 

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • PS3 only, but write brief json description and import the object.