【问题标题】:how to format output of expanded variable如何格式化扩展变量的输出
【发布时间】:2013-06-17 14:06:14
【问题描述】:

我正在尝试使变量等于查询的输出,但是我可以通过管道传递到另一个命令,但它没有按我希望的那样工作。这就是我所拥有的。

$office=get-aduser "samaccountname" -properties * |选择办公室

我已经尝试过使用子表达式 $folder= get-aduser "samaccountname" -properties * |选择“$(办公室)”和 @{n='office';e={$_.office -replace '^office='$1'}} 两者都没有删除@{office=} 我的目标是得到 $office=office 但我得到的是 $office=@{office=}

如何从输出中删除 @{}?

【问题讨论】:

    标签: variables powershell format output


    【解决方案1】:

    这是你需要做的:

    $office = (Get-ADUser "samAccountName" -properties office).Office
    

    编辑

    另一种方式(可能更容易理解也可能不容易理解)是:

    $user = Get-ADUser "samAccountName" -properties office
    $office = $user.office
    

    【讨论】:

    • 太好了,很高兴我能帮上忙。这里我们首先执行括号中的表达式,然后返回 Office 属性的值。修改后的答案。
    猜你喜欢
    • 2010-09-23
    • 1970-01-01
    • 2013-10-23
    • 1970-01-01
    • 1970-01-01
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    相关资源
    最近更新 更多