2

I have searched around (including) this forum and seen comments about this but can not get it to work.

I have a variable in PS $user.accountname = Aaron.street"

But as bellow if i type the name in full it works but not using the variable. I have tried so mane suggestions from searching this forum but nothing seems to work.

    PS D:\Lync PS scripts> Get-adUser -Filter "name -like 'Aaron Street'"


DistinguishedName : CN=aaron street,OU=Full_time,OU=Staff,OU=Accounts,OU=.........
Enabled           : True
GivenName         : aaron
Name              : aaron street
ObjectClass       : user
ObjectGUID        : 037c744b-63fa-4a18-adb3-........
SamAccountName    : street
SID               : S-1-5-21-33161136-...........
Surname           : street
UserPrincipalName : street@...........




PS D:\Lync PS scripts> Get-adUser -Filter "name -like '$user.Accountname'"

PS D:\Lync PS scripts> Write-Host $user.AccountName
Aaron Street

What I want is to find the user and then update a property using another variable "$user.number" So my full command would be

get-aduser -filter "name -like '$user.accountname'" | set-aduser -Replace @{Officephone = $user.Number}

Any thoughts on where I am going wrong with using the variables?

1 Answer 1

2

You need to use a subexpression to expand the variable correctly

Get-adUser -Filter "name -like '$($user.Accountname)'"
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, I will look that up later (PS in not my skill set as you can tell) what its doing. But in the mean time thank you very much for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.