0

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 Answer 1

0

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
1
  • Great, glad I could help.. Here we are executing the expression in the Parentheses first and then returning the value of the Office property. Revised Answer.
    – AndyMeFul
    Jun 19, 2013 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.