ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Anyone have a powershell line to create a new admin account

    IT Discussion
    windows 7 administrators powershell
    7
    18
    1.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch
      last edited by

      I have a handful of Windows 7 machiens not on a domain.

      I want to put a new Admin account on them.

      The current user accounts have admin rights, which I will remove, I have ScreenConnect installed and running with admin perms. So I can pop a powershell via the ScreenConnect command window easily to do this.

      thwrT matteo nunziatiM 2 Replies Last reply Reply Quote 2
      • DustinB3403D
        DustinB3403
        last edited by

        Here is a script on Microsoft's website, but it needs to be adjusted.

        You can likely do this with a simplified command as well ..

        1 Reply Last reply Reply Quote 0
        • DustinB3403D
          DustinB3403
          last edited by

          This one seems like it was written this decade over the other one I linked.

          https://gist.github.com/ducas/3a65704a3b92dfa0301e

          1 Reply Last reply Reply Quote 1
          • black3dynamiteB
            black3dynamite
            last edited by black3dynamite

            Within a powershell script

            cmd.exe /c "net user adminuser password /add"
            cmd.exe /c "net localgroup administrators adminuser /add"
            cmd.exe /c "wmic path Win32_UserAccount where Name='adminuser' set PasswordExpires=false"
            
            #To remove Users group from adminuser and only have Administrators
            cmd.exe /c "net localgroup users adminuser /del"
            
            JaredBuschJ 1 Reply Last reply Reply Quote 2
            • JaredBuschJ
              JaredBusch @black3dynamite
              last edited by

              @black3dynamite said in Anyone have a powershell line to create a new admin account:

              Within a powershell script

              cmd.exe /c "net user adminuser password /add"
              cmd.exe /c "net localgroup administrators adminuser /add"
              cmd.exe /c "wmic path Win32_UserAccount where Name='adminuser' set PasswordExpires=false"
              
              #To remove Users group from adminuser and only have Administrators
              cmd.exe /c "net localgroup users adminuser /del"
              

              I have that, but I swear I did it with powershell once but cannot find what I did.

              /me rants about needing better notes.

              1 Reply Last reply Reply Quote 0
              • ObsolesceO
                Obsolesce
                last edited by Obsolesce

                New-LocalUser -Name "SpongeBob" -Description "Badass Admin"
                Add-LocalGroupMember -Group "Administrators" -Member "SpongeBob"
                

                New-LocalUser
                https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1

                Add-LocalGroupMember
                https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/add-localgroupmember?view=powershell-5.1

                black3dynamiteB 1 Reply Last reply Reply Quote 3
                • black3dynamiteB
                  black3dynamite @Obsolesce
                  last edited by black3dynamite

                  @tim_g said in Anyone have a powershell line to create a new admin account:

                  New-LocalUser -Name "SpongeBob" -Description "Badass Admin"
                  Add-LocalGroupMember -Group "Administrators" -Member "SpongeBob"
                  

                  New-LocalUser
                  https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1

                  Add-LocalGroupMember
                  https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/add-localgroupmember?view=powershell-5.1

                  Windows Management Framework 5.1 needs to be installed on Windows 7.
                  https://www.microsoft.com/en-us/download/details.aspx?id=54616

                  You can find out the current version on Windows 7 with this command in PowerShell.
                  $PSVersionTable.PSVersion

                  JaredBuschJ 1 Reply Last reply Reply Quote 1
                  • ObsolesceO
                    Obsolesce
                    last edited by

                    Or if you use SaltStack:

                    https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.win_useradd.html

                    black3dynamiteB 1 Reply Last reply Reply Quote 1
                    • black3dynamiteB
                      black3dynamite @Obsolesce
                      last edited by

                      @tim_g said in Anyone have a powershell line to create a new admin account:

                      Or if you use SaltStack:

                      https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.win_useradd.html

                      Those commands looks so much easier to use.

                      ObsolesceO 1 Reply Last reply Reply Quote 0
                      • ObsolesceO
                        Obsolesce @black3dynamite
                        last edited by

                        @black3dynamite said in Anyone have a powershell line to create a new admin account:

                        @tim_g said in Anyone have a powershell line to create a new admin account:

                        Or if you use SaltStack:

                        https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.win_useradd.html

                        Those commands looks so much easier to use.

                        SaltStack makes management extremely easier

                        1 Reply Last reply Reply Quote 1
                        • thwrT
                          thwr @JaredBusch
                          last edited by

                          @jaredbusch said in Anyone have a powershell line to create a new admin account:

                          I have a handful of Windows 7 machiens not on a domain.

                          I want to put a new Admin account on them.

                          The current user accounts have admin rights, which I will remove, I have ScreenConnect installed and running with admin perms. So I can pop a powershell via the ScreenConnect command window easily to do this.

                          AD? New-ADuser or so. On the road ATM, can check later

                          JaredBuschJ 1 Reply Last reply Reply Quote 1
                          • JaredBuschJ
                            JaredBusch @thwr
                            last edited by

                            @thwr said in Anyone have a powershell line to create a new admin account:

                            @jaredbusch said in Anyone have a powershell line to create a new admin account:

                            I have a handful of Windows 7 machiens not on a domain.

                            I want to put a new Admin account on them.

                            The current user accounts have admin rights, which I will remove, I have ScreenConnect installed and running with admin perms. So I can pop a powershell via the ScreenConnect command window easily to do this.

                            AD? New-ADuser or so. On the road ATM, can check later

                            Local user.

                            1 Reply Last reply Reply Quote 0
                            • JaredBuschJ
                              JaredBusch @black3dynamite
                              last edited by

                              @black3dynamite said in Anyone have a powershell line to create a new admin account:

                              @tim_g said in Anyone have a powershell line to create a new admin account:

                              New-LocalUser -Name "SpongeBob" -Description "Badass Admin"
                              Add-LocalGroupMember -Group "Administrators" -Member "SpongeBob"
                              

                              New-LocalUser
                              https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1

                              Add-LocalGroupMember
                              https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/add-localgroupmember?view=powershell-5.1

                              Windows Management Framework 5.1 needs to be installed on Windows 7.
                              https://www.microsoft.com/en-us/download/details.aspx?id=54616

                              You can find out the current version on Windows 7 with this command in PowerShell.
                              $PSVersionTable.PSVersion

                              well fuck..
                              0_1517335976163_5d24ba6b-28fc-45fe-b08c-21f50b7e2e6d-image.png

                              ObsolesceO 2 Replies Last reply Reply Quote 1
                              • ObsolesceO
                                Obsolesce @JaredBusch
                                last edited by

                                @jaredbusch said in Anyone have a powershell line to create a new admin account:

                                @black3dynamite said in Anyone have a powershell line to create a new admin account:

                                @tim_g said in Anyone have a powershell line to create a new admin account:

                                New-LocalUser -Name "SpongeBob" -Description "Badass Admin"
                                Add-LocalGroupMember -Group "Administrators" -Member "SpongeBob"
                                

                                New-LocalUser
                                https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/new-localuser?view=powershell-5.1

                                Add-LocalGroupMember
                                https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.localaccounts/add-localgroupmember?view=powershell-5.1

                                Windows Management Framework 5.1 needs to be installed on Windows 7.
                                https://www.microsoft.com/en-us/download/details.aspx?id=54616

                                You can find out the current version on Windows 7 with this command in PowerShell.
                                $PSVersionTable.PSVersion

                                well fuck..
                                0_1517335976163_5d24ba6b-28fc-45fe-b08c-21f50b7e2e6d-image.png

                                Lol

                                1 Reply Last reply Reply Quote 0
                                • ObsolesceO
                                  Obsolesce @JaredBusch
                                  last edited by

                                  @jaredbusch Looks like SaltStack is the way to go. PSTools makes it easy too if you need a quick n easy.

                                  JaredBuschJ 1 Reply Last reply Reply Quote 1
                                  • JaredBuschJ
                                    JaredBusch @Obsolesce
                                    last edited by

                                    @tim_g said in Anyone have a powershell line to create a new admin account:

                                    @jaredbusch Looks like SaltStack is the way to go. PSTools makes it easy too if you need a quick n easy.

                                    old cmd line will work. jsut not what I wanted to do.

                                    DashrenderD 1 Reply Last reply Reply Quote 2
                                    • DashrenderD
                                      Dashrender @JaredBusch
                                      last edited by

                                      @jaredbusch said in Anyone have a powershell line to create a new admin account:

                                      @tim_g said in Anyone have a powershell line to create a new admin account:

                                      @jaredbusch Looks like SaltStack is the way to go. PSTools makes it easy too if you need a quick n easy.

                                      old cmd line will work. jsut not what I wanted to do.

                                      run each command from SC.. not as fast as one click.. but still not bad.

                                      1 Reply Last reply Reply Quote 0
                                      • matteo nunziatiM
                                        matteo nunziati @JaredBusch
                                        last edited by

                                        @jaredbusch said in Anyone have a powershell line to create a new admin account:

                                        I have a handful of Windows 7 machiens not on a domain.

                                        I want to put a new Admin account on them.

                                        The current user accounts have admin rights, which I will remove, I have ScreenConnect installed and running with admin perms. So I can pop a powershell via the ScreenConnect command window easily to do this.

                                        not tested... maybe this thread can help with PS 2.0. Quoting code here:

                                        # Create new local Admin user for script purposes
                                        $Computer = [ADSI]"WinNT://$Env:COMPUTERNAME,Computer"
                                        
                                        $LocalAdmin = $Computer.Create("User", "LocalAdmin")
                                        $LocalAdmin.SetPassword("Password01")
                                        $LocalAdmin.SetInfo()
                                        $LocalAdmin.FullName = "Local Admin by Powershell"
                                        $LocalAdmin.SetInfo()
                                        $LocalAdmin.UserFlags = 64 + 65536 # ADS_UF_PASSWD_CANT_CHANGE + ADS_UF_DONT_EXPIRE_PASSWD
                                        $LocalAdmin.SetInfo()
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • 1 / 1
                                        • First post
                                          Last post