【发布时间】:2015-01-02 15:26:13
【问题描述】:
以下代码行给我一个管道错误:
$user.name + "|" + $user.DisplayName | Out-File $output -Append
"Managing Group: " | + $_.name + "|" +`
" Group Description: " + ($_.description -replace "`r`n", " ") | Out-File $output -Append
我已尝试将部分代码替换为:
(& { process{$_.description -replace "`r`n", " "}} )
(foeach-object{$_.description -replace "`r`n", " "} )
%{$_.description -replace "`r`n", " "}
但似乎没有什么能解决这个错误。
错误:
表达式只能作为管道的第一个元素。在 C:\AD-User.MonitorAll.ps1:92 字符:82 + " 组描述:" + ($_.description -replace "
rn", " ")
更新:
我的问题是我错过了 |在“管理组:”之后
$user.name + "|" + $user.DisplayName | Out-File $output -Append
"Managing Group: " + "|" + $_.name + "|" +`
" Group Description: " + ($_.description -replace "`r`n", " ") | Out-File $output -Append
【问题讨论】:
-
我拆分了代码行,因为我得到了相当长的“管理组”列表,所以我希望名称和显示名称在它自己的行上 - 仅供参考
-
你想用
|分隔符输出这个吗?如果是这样,还有更清洁的方法。 -
是的,我正在使用 |作为分隔符
-
是的,我刚刚做了。谢谢! :)
-
请不要使用“更新”或“已回答”类型的文本更新标题。将问题标记为答案也有同样的目的。
标签: powershell output pipeline