Difference between PSObject, Hashtable, and PSCustomObject

后端 未结 5 1058
甜味超标
甜味超标 2020-12-02 17:01

Can anybody explain the details? If I create an object using

$var = [PSObject]@{a=1;b=2;c=3}

and then I look for its type using getTy

5条回答
  •  我在风中等你
    2020-12-02 17:40

    Say I want to create a folder. If I use a PSObject you can tell it is wrong by looking at it

    PS > [PSObject] @{Path='foo'; Type='directory'}
    
    Name                           Value
    ----                           -----
    Path                           foo
    Type                           directory
    

    However the PSCustomObject looks correct

    PS > [PSCustomObject] @{Path='foo'; Type='directory'}
    
    Path                                    Type
    ----                                    ----
    foo                                     directory
    

    I can then pipe the object

    [PSCustomObject] @{Path='foo'; Type='directory'} | New-Item
    

提交回复
热议问题