Announcement

Collapse
No announcement yet.

A script to change usernames?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • A script to change usernames?

    Over the last couple years we have varied on the usernames for our admin accounts, I'm trying to find a script to change all the entered usernames into x; example:

    I want to tell it that if username=A,B, or C to change it to P

    Is there such a script to do this, and what language would it be in?

    Edit: A program that works like pspassword would work for us too as long as it does windows usernames.
    Last edited by Managor; 23rd March 2011, 19:12.
    "To err is human but to really **** things up requires a computer user..."

    "The path to enlightenment is /user/bin/enlightenment"

    A+ CE

  • #2
    Re: A script to change usernames?

    Are these local or domain accounts?

    The language for such a script would be anything that supports talking to AD or running other executables such as dsmod.

    Have a go at the script and post your progress so that we can start to offer some help with it.
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

    Comment


    • #3
      Re: A script to change usernames?

      Originally posted by gforceindustries View Post
      Are these local or domain accounts?

      The language for such a script would be anything that supports talking to AD or running other executables such as dsmod.
      They would be local accounts on remote computers.

      So I don't think dsmod would work.

      Have a go at the script and post your progress so that we can start to offer some help with it.
      I wish I had the knowledge to script this type of thing, it would make it a ton easier on myself. I've been doing some Google searching, and playing around with Microsofts "scriptomatic", but I still can't find a place to start from; other then this, I've only found scripts to change password, and since I have a script for password management already, I'm still struggling to find a script/program to change local user account names. That's why I asked you guys. I'm also trying to find out if it's even possible, and if so, what methods make it possible, if not what method I could use to try to sort-of create the effect.

      I forgot to mention, this would need to work on XP Pro and Windows 7 Pro.
      Last edited by Managor; 24th March 2011, 14:59.
      "To err is human but to really **** things up requires a computer user..."

      "The path to enlightenment is /user/bin/enlightenment"

      A+ CE

      Comment


      • #4
        Re: A script to change usernames?

        Originally posted by Managor View Post
        Over the last couple years we have varied on the usernames for our admin accounts, I'm trying to find a script to change all the entered usernames into x; example:

        I want to tell it that if username=A,B, or C to change it to P

        Is there such a script to do this, and what language would it be in?

        Edit: A program that works like pspassword would work for us too as long as it does windows usernames.
        Can you simply not better,
        - Remove all user accounts from the local group Administrators (or deleted those users from the computer if you like)
        - add a new local user account when ithe name does not exist already.
        - Then add the new user (by name) to this group if it is not a member already.
        - set a password on the account
        You can do it all with a startup script.

        Additionally,, Members of local groups can be controlled by GPO -> "Restricted Groups" -policy.

        \Rems
        Last edited by Rems; 24th March 2011, 16:15.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: A script to change usernames?

          As I said above, they are not AD users.

          We are also trying to keep the files on the accounts, which is why I'm wanting to change names instead of making new accounts.
          "To err is human but to really **** things up requires a computer user..."

          "The path to enlightenment is /user/bin/enlightenment"

          A+ CE

          Comment


          • #6
            Re: A script to change usernames?

            Originally posted by Managor View Post
            As I said above, they are not AD users.
            Yes I was aware of that, did I mession domain user somewhere? I didn't knew that keeping ownership of files was important.

            The computers are clients not? Using GPOs is possible?



            how-can-i-rename-a-local-user-account-on-a-windows-xp-computer


            \Rems
            Last edited by Rems; 24th March 2011, 18:19.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: A script to change usernames?

              Originally posted by Managor View Post
              They would be local accounts on remote computers.
              WMI is the answer. Use Win32_UserAccount.Rename(). VBScript or Powershell works fine. Here is an example on renaming some local accounts, should be easy to convert to remote system.

              -vP

              Comment


              • #8
                Re: A script to change usernames?

                Quick question, if I wanted to do Username's "PL" and "P L" both into "P_L" in the same script, would this be the correct method?

                Code:
                strComputer = "."
                
                Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
                Set colAccounts = objWMIService.ExecQuery _
                    ("Select * From Win32_UserAccount Where LocalAccount = True And Name = 'PL'")
                    ("Select * From Win32_UserAccount Where LocalAccount = True And Name = 'P L'")
                
                For Each objAccount in colAccounts
                    objAccount.Rename "P_L"
                Next
                Last edited by Managor; 25th March 2011, 14:44.
                "To err is human but to really **** things up requires a computer user..."

                "The path to enlightenment is /user/bin/enlightenment"

                A+ CE

                Comment

                Working...
                X