Add-Admin.ps1 powershell script to add users to local Administrators group

This script adds one or more users to local Administrators group on one or more computers. For more details see this post.To use it, download it, unblock the file, run it in Powershell_ISE for example to load  the function, and use it as in:Powershell displays help output like:NA

Add-Admin.ps1
 
 
 
 
 
3 Star
(2)
6,546 times
Add to favorites
11/9/2014
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • How can I use account name as input file
    1 Posts | Last post April 05, 2019
    • Hi,
      
      Thanks for the script! 
      
      Is there any way to pass the computer names and account names as input file? It means, we provide an input file, which contains computer names and user names, which we want to add them into local admin group of the server? 
      
      User Name Computer Name 
      User A     Comp A 
      User B     Comp A
      User C     Comp B
      
      Thanks
      Amir
  • Set password to never expire
    1 Posts | Last post January 02, 2018
    • Hi,
      It works, but is there a way to set the password to never expire?
  • Check local Administrators group Name
    1 Posts | Last post March 27, 2017
    • Hello,
      It could be useful to check the administrators group name to support non-english OS, for example with this command :
      Get-WmiObject win32_group -filter "LocalAccount = $TRUE And SID = 'S-1-5-32-544'" -Compute
      rName $computer | select -expand name
  • Same error as below user
    5 Posts | Last post August 03, 2016
    • I got the same error.
      
      PS C:\Users\tsmadmin\Desktop> .\Add-Admin.ps1 -ComputerName pruebapc -NewAdmin P
      rueba
      You must provide a value expression on the right-hand side of the '-' operator.
      At C:\Users\tsmadmin\Desktop\Add-Admin.ps1:202 char:44
      +                         if ($NewAdminName - <<<< in $DomainAdmins) {
          + CategoryInfo          : ParserError: (:) [], ParseException
          + FullyQualifiedErrorId : ExpectedValueExpression
    • Dot source the script to load the add-admin function, then call the function as in:
      
      .\Add-Admin.ps1 
      
      Add-Admin -ComputerName pruebapc -NewAdmin Prueba -NewAdminPassword Password1 -CurrentAdmin samb
      
      
    • well,
      
      first of all the script requirements are missing, it is made for PS v3.0+
      
      to be able to run it in PS 2.0
      you need to make next modifications:
      replace lines 191-194
      with
      "
                  $Group = Get-wmiobject -Class Win32_Group -ComputerName $Computer -Filter "Name = 'Administrators'"
                  $Groupname = $Group.name
                  $LocalAdmins = Get-WmiObject -Class win32_groupuser -ComputerName $Computer | Where-Object { $_.GroupComponent -match $Groupname} | ForEach-Object {[wmi]$_.PartComponent }
                  $LocalAdmins = $LocalAdmins | select -expandproperty name
      "
      replace line 202
      with
      "
      if ($DomainAdmins -contains $NewAdminName) {
      "
      replace line 220
      with
      "
      if ($LocalAdmins -contains $AdminName) {
      "
    • and next Dot source the script to load the add-admin function, 
      . .\Add-Admin.ps1 (pls notice additional "dot" before the script"
      
      then call the function as in documentation:
      Add-Admin -ComputerName pruebapc -NewAdmin Prueba -NewAdminPassword Password1 -CurrentAdmin samb
    • and also pls notice the "space" between two dots
  • Error
    1 Posts | Last post April 09, 2016
    • PS C:\Users\tsmadmin\Desktop> .\Add-Admin.ps1 -ComputerName pruebapc -NewAdmin P
      rueba
      You must provide a value expression on the right-hand side of the '-' operator.
      At C:\Users\tsmadmin\Desktop\Add-Admin.ps1:202 char:44
      +                         if ($NewAdminName - <<<< in $DomainAdmins) {
          + CategoryInfo          : ParserError: (:) [], ParseException
          + FullyQualifiedErrorId : ExpectedValueExpression