How do I concatenate text to the beginning of a piped variable?

Hi,

The goal is to concatenate text to the beginning of a variable passed in the pipeline and used to set a variable as follows:

Get-Aduser MyID -Pr EMailAddress | Set-Aduser -EmailAddress TXT$_.EmailAddress

So I want to add some text to the beginning of the EmailAddress for an account.  I tried a combo of things, but not succe

August 22nd, 2015 11:01am

Try double quotes around the text and $_.EmailAddress.
Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2015 12:41pm

 Get-Aduser MyID -Properties  EMailAddress |
     %{$_|Set-Aduser -EmailAddress "TXT$($_.EmailAddress)"}

August 22nd, 2015 1:03pm

As you can see, you may need to include the subexpression $() operator -- oops. Thanks, jrv.
Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2015 1:06pm

Thanks for the responses.

Jrv: The subexpression works, however I needed to add a -Identity $_.SamAccountName parameter to the Set-Aduser or else it prompts me for Identity.  I don't understand why I would be prompted.

I tried the double quotes and various combos of concatenation and nothing worked.  Can you plz suggest where I can get a good understand of subexpressions and how they work.

Thanks again for the help.

August 22nd, 2015 2:07pm

 Get-Aduser MyID -Properties  EMailAddress |
     %{$_|Set-Aduser -EmailAddress "TXT$($_.EmailAddress)"}

Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2015 2:18pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics