Adding to the expression

Welcome Forums General PowerShell Q&A Adding to the expression

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 years, 1 month ago.

  • Author
    Posts
  • #54824

    Participant
    Points: 0
    Rank: Member

    Really stupid question here that is best explained with an example:

    get-aduser tuser| Select @{n='testname';e={$_.samaccountname}}

    I want to add to the end of the samaccountname like:

    get-aduser tuser| Select @{n='testname';e={$_.samaccountname}"SOMETHINGELSE"}

    I know it's something simple but I just don't know how to format it.

    Just learning here 🙂

    Thanks,
    Scott

  • #54826

    Participant
    Points: 10
    Rank: Member
    @{n='testname';e={"$($_.samaccountname)SOMETHINGELSE"}}
    
  • #54827

    Participant
    Points: 0
    Rank: Member

    The part inside the {} will evaluate any code and return the results, so you can use any method for creating and joining strings. One example:

    @{n='testname';e={"$($_.samaccountname)SOMETHINGELSE"}}
  • #54828

    Participant
    Points: 0
    Rank: Member

    Perfect! I knew it was something simple.

    Thanks for not making me feel stupid...lol

The topic ‘Adding to the expression’ is closed to new replies.