How do I create a custom type in PowerShell for my scripts to use?

后端 未结 8 1291
遥遥无期
遥遥无期 2020-12-22 18:29

I would like to be able to define and use a custom type in some of my PowerShell scripts. For example, let\'s pretend I had a need for an object that had the following struc

8条回答
  •  北海茫月
    2020-12-22 19:00

    Surprised no one mentioned this simple option (vs 3 or later) for creating custom objects:

    [PSCustomObject]@{
        First = $First
        Last = $Last
        Phone = $Phone
    }
    

    The type will be PSCustomObject, not an actual custom type though. But it is probably the easiest way to create a custom object.

提交回复
热议问题