String concatenate not working

Welcome Forums General PowerShell Q&A String concatenate not working

Viewing 4 reply threads
  • Author
    Posts
    • #257936
      Participant
      Topics: 2
      Replies: 5
      Points: 37
      Rank: Member

      Hi Guys,

      I’m trying to create Samaccountname based on the firstname and lastname in csv file.

      $adusers.lastname.substring(0,4)   with this command, I was able to get the first 4 letters from lastname and similarly was able to pull the first two letters from firstname. 

      This is our organization naming convention.

      samaccount will start with U or V and followed by First 4 letters from last name and First 2 letters from first name. The csv will have a column that states employee type. If it is full-time employee, the sam ID should start with U. If any other category it should start with U.

      e.g-> Wayne Rooney

      UROONWA – Full Time

      VROONWA – Part time or consultancy ..etc

      I’m very new to PowerShell any help will be greatly appreciated.

      I ran the below cmd without $(), I got some error message. I used subexpression $() and after that, I got the below message

       

       

      Commands which I was trying:

      I tried both join and concatenate,

      This is the message I get:

       

      Please help

       

       

      • This topic was modified 3 weeks, 6 days ago by Thiru.
    • #258107
      Participant
      Topics: 8
      Replies: 606
      Points: 2,342
      Helping Hand
      Rank: Community Hero

      Thiru,

      When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to you help making their work twice or more.

      https://www.reddit.com/r/PowerShell/comments/ixo27c/samaccountname_genration_string_concatenation_not/

      Thanks

      • This reply was modified 3 weeks, 6 days ago by Doug Maurer.
      • #258122
        Participant
        Topics: 2
        Replies: 5
        Points: 37
        Rank: Member

        Sure, Doug. Noted

    • #258113
      Participant
      Topics: 8
      Replies: 606
      Points: 2,342
      Helping Hand
      Rank: Community Hero

      No need to over complicate it, you can concatenate with + easily.

      Output

      You can also use string interpolation

    • #258161
      Participant
      Topics: 5
      Replies: 331
      Points: 536
      Helping Hand
      Rank: Major Contributor
    • #258785
      Participant
      Topics: 2
      Replies: 5
      Points: 37
      Rank: Member

      Hi Rob,

      Thanks for your reply.

      I read the script from the URL. I could see you are using PSBoundParameters to generate strings based on the variable and progressing using Begin, Process & End scripts.

      I don’t understand in detail of Begin, process, and end, however I tried to reuse the script with my little understanding. This is my first PowerShell script. I’m building it part by part and looking for a way to conjunct everything. Maybe this is a bad approach. But this is where I stand right now.

      • creating variable to inputfile
      • assinging variable to all my csv data
      • If AD account exisit, modify the account. (Actually this is not working,)

      If I run the below command along with the top of the script. It is writing the employee ID, when I add multiple attributes seperated by ;, it giving me an error

      Error:

       

      cont-

      • else generate the SAMID
      • From here, I used your scripts, but i need help on joining those.
      • And have to find a way to parse the information to New-ADuser cmdlet (Right now i’m using IF, I think that is not right)

      Can you tell me what logic I should use once I created the SAMID,

      • Checking it with AD
      • IF exisit, increment with number
      • And to create the AD account

       

       

Viewing 4 reply threads
  • You must be logged in to reply to this topic.