none
How to select Specific string after a character RRS feed

  • Question

  • Hi,

    while creating a user account in discription bar we have the ticket number - Name of owner = managers email id. This format is shown as ex in discription tab of user properties.

    INC000233 - Alex B = john_fed@domain.com

    How can i collect string after character "=" i.e john_fed@domain.com? i tried to use the select string cmdlet but it gives the complete string.

    Please suggest.

    Monday, May 5, 2014 12:27 PM

Answers

  • I would also recommend to use the trim method to clean up the leading space between the equals sign and the beginning of the email address.

     


    Monday, May 5, 2014 2:01 PM

All replies

  • Hi Amitkumar,

    there are several ways to do this. For example you can do this by splitting the string and selecting the second element:

    $a = "INC000233 - Alex B = john_fed@domain.com"
    $a.Split("=")[1]

    Strings have quite a few interesting functions, you can easily get a list by using this command:
    "a" | gm

    A fine introduction to basic string manipulation can be found here.

    Cheers,
    Fred


    There's no place like 127.0.0.1


    • Edited by FWN Monday, May 5, 2014 1:08 PM
    • Proposed as answer by Mike Laughlin Monday, May 5, 2014 2:01 PM
    Monday, May 5, 2014 1:08 PM
  • I'd make one small adjustment to Fred's code to trim off the leading space:

    $a = "INC000233 - Alex B = john_fed@domain.com"
    $a.Split("=")[1].Trim()


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    Monday, May 5, 2014 2:01 PM
  • I would also recommend to use the trim method to clean up the leading space between the equals sign and the beginning of the email address.

     


    Monday, May 5, 2014 2:01 PM
  • Hi Tommy,

    Thanks it really works and help me. One last daught. There are few entries which are in given format like

    Description - This generic Id is created for test - Luck_Don@domain .com

    So here it gives me error like

    You cannot call a method on a null-valued expression.
    At line:8 char:33
    + $email = $des.split("=")[1].trim <<<< ()
        + CategoryInfo          : InvalidOperation: (trim:String) [], RuntimeExcep
       tion
        + FullyQualifiedErrorId : InvokeMethodOnNull
     

    I think, this error is popped up becasue " sign is not present at the end of email id. Any idea how to solve this.

    Wednesday, May 7, 2014 12:58 PM
  • One more point. If i remove trim() then it gives the email id with space.

    thnaks

    Wednesday, May 7, 2014 1:00 PM