how to format output of expanded variable

…衆ロ難τιáo~ 提交于 2019-12-13 04:38:52

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/17149559/how-to-format-output-of-expanded-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!