问题
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