如何格式化扩展变量的输出 [英] how to format output of expanded variable
问题描述
$ 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
pre>
$ office = $ user.office
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屋!