小编Dro*_*ick的帖子

如何在 powershell 中正确管道对象以避免“表达式仅允许作为管道的第一个元素”错误

有没有办法在不创建对象 $obj 的情况下执行以下操作?

$obj = New-Object System.Security.Principal.NTAccount("Students") ; $obj.Translate([System.Security.Principal.SecurityIdentifier]).Value
Run Code Online (Sandbox Code Playgroud)

我尝试过管道,如下所示:

New-Object System.Security.Principal.NTAccount("Students") | $_.Translate([System.Security.Principal.SecurityIdentifier]).Value
Run Code Online (Sandbox Code Playgroud)

但出现以下错误:

Expressions are only allowed as the first element of a pipeline.
At line:1 char:128
+ New-Object System.Security.Principal.NTAccount("Students") | $_.Translate([System.Security.Principal.SecurityIdentifi
er]).Value <<<<
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
Run Code Online (Sandbox Code Playgroud)

提前致谢!

windows powershell

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1

windows ×1