PowerTip: The Easy Way to Create a Custom PowerShell Object

Doctor Scripto

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

 

0 comments

Discussion is closed.

Feedback usabilla icon