Report User details strip out characters?

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Vern Anderson Vern Anderson 2 years, 7 months ago.

  • Author
    Posts
  • #14893
    Profile photo of Jake Sully
    Jake Sully
    Participant

    Hello,

    I am working on a script that will gather user details such as basics like the DisplayName, Description, Employee ID #, and Telephone Number.

    The challenge is that I have to remove some of the phone number. I want to keep only the last 8 characters, which should (in 99% of instances) be 765-4321

    Can anyone help me do this? I have to query AD using Quest as we have a Windows 2003 domain with no AD Web Services running. I can get the user details for all users in the domain, but I think I've got to limit this to a 1 main OU and sub-ous under that main OU, that's the only part of the gathering data I think I need some help with. Then I think I was ok with the rest, but any help would be great. The end result is I need to send this out as an email or perhaps save it to a file share in csv format.

    Thanks as always, you are all great!
    Jake

  • #14899
    Profile photo of Vern Anderson
    Vern Anderson
    Participant

    It would be helpful if you could post the exact string you're getting back. You could replace the phone number with all 5's but it would help to see what you're up against.

    In PowerShell generally speaking you would probably use the replace method or the -replace operator. However if you can master the discipline of regex (Regular Expresions) it is a more powerful way of dealing with this sort of an problem.

    # The Replace Method takes arguments in the parenthesis 2 strings separated by a comma the left most being what you want to get rid of the right being what to replace it with

    $phonenumber = "{ 210-555-5555 }".Replace("{","").Replace("}","").Replace(" ","")

    # The -replace Operator work the same way as the method but may be a better option and if I see the real string I can help more


    $phonenumber = "{ 210-555-5555 }"
    $phonenumber = $phonenumber -replace "{" , "" # The empty quotes after the comma tell it to replace with "nothing"
    $phonenumber = $phonenumber -replace "}" , ""
    $phonenumber = $phonenumber -replace " " , ""

  • #14900
    Profile photo of Vern Anderson
    Vern Anderson
    Participant

You must be logged in to reply to this topic.