Powershell:在select-object中转换对象

时间:2015-09-26 01:45:02

标签: powershell

我想在Select-Object

中投射一个对象

我似乎无法正确理解语法:(

Select-Object `
                @{name='a';expression={$path}}, `
                @{name='b';expression={$folder}}, `
                @{Name='c';expression={ [System.Security.Principal.SecurityIdentifier]$_.IdentityReference.Translate([System.Security.Principal.NTAccount]).Value}}, `
                @{Name='SID';expression={$_.IdentityReference}}

继续变空字符串。

有什么想法吗?

编辑:我应该提到我在这里要做的事情。 IdentityReference似乎在给我一个SID,我只是想把它转换成名字。

@briantist - 是的,演员在外面工作,试试我开始的([System.Security.Principal.SecurityIdentifier]"S-1-5-XX-VALID-SID-HERE").Translate([System.Security.Principal.NTAccount]).Value

@TessellatingHeckler $_.IdentityReference.Translate([System.Security.Principal.SecurityIdentifier])没有伤心地工作。

1 个答案:

答案 0 :(得分:0)

你可以发布更多代码吗?
这对我有用:

Select-Object `
            @{name='a';expression={$path}}, `
            @{name='b';expression={$folder}}, `
            @{Name='c';expression={((New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "SID").Translate([System.Security.Principal.NTAccount])).Value}}, `
            @{Name='SID';expression={$_.IdentityReference}}


替换为输入。

  

-ArgumentList“SID”