如何格式化扩展变量的输出 [英] how to format output of expanded variable

查看:161
本文介绍了如何格式化扩展变量的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个变量等于查询的输出,但我可以管到另一个命令,但它不工作,如我所希望的。这里是我的。



$ office = get-adusersamaccountname-properties * |选择办公室

我已经尝试过使用子表达式$ folder = get-adusersamaccountname-properties * |选择'$(office)'和
@ {n ='office'; e = {$ _。office -replace'^ office ='$ 1'}}两者都不能删除@ {office =}
我的目标是获得$ office = office,而我得到$ office = @ {office =}

如何从输出中删除@ {}

解决方案



pre > $ office =(Get-ADUsersamAccountName-properties office).Office



<
$ b $ p另一种方法(这可能会也可能不容易理解)是:

  $ user = Get-ADUsersamAccountName-properties office 
$ office = $ user.office
pre>

I am trying to make a variable equal the output of query but so i can pipe to another command but its not working as i hoped. here is what i have.

$office=get-aduser "samaccountname" -properties * | select office

I already tried using sub-expressions $folder= get-aduser "samaccountname" -properties * | select '$(office)' and @{n='office';e={$_.office -replace '^office='$1'}} neither of which remove the @{office=} My goal is to get $office=office but instead i get $office=@{office=}

How do you remove the @{} from the output?

解决方案

This is what you need to do:

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

EDIT

Another way (which may or may not be easier to understand) is:

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

这篇关于如何格式化扩展变量的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆