Create local user as part of Administrator group on Windows 10 RRS feed

  • Question

  • Setup:

    We are all in domain environment. Active Directory is Windows Server 2012 R2

    Client Workstations are mix of Windows 10 versions (1703 and 1709)

    Need to create user "Servis" on all workstation and place it to local Administrator group. I will input a text file with the host names.

    This is the script im trying to make it work, but no success.

    The user is created, but user is not added to local admin group.

    This is the error i get :

    Error creating Service23 on WinNT://WS-TEST:  The following exception occurred while retrieving member "add": "The network path was not found.

    $computers = Get-Content -path C:\Scripts\CreateLocalUser\New\Computers.txt
    $username = "Servis"
    $password = "P4$$w0rd!@#"
    Foreach($computer in $computers)
    $users = $null
    $computer = [ADSI]"WinNT://$computername"
    Try {
       $users = $computer.psbase.children | select -expand name
       if ($users -like $username) {
          Write-Host "$username already exists"  -ForegroundColor Green
       } Else {
          $user_obj = $computer.Create("user", "$username")
          $user_obj.Put("description", "$username")
          $user_obj.psbase.invokeset("AccountDisabled", "False")
          $users = $computer.psbase.children | select -expand name
          if ($users -like $username) {
             Write-Host "$username has been created on $($computer.name)"
          $group = [ADSI]("WinNT://"+$computername+"/administrators,group")
          } Else {
             Write-Host "$username has not been created on $($computer.name)"
    } Catch {
       Write-Host "Error creating $username on $($computer.path):  $($Error[0].Exception.Message)"

    Tuesday, June 19, 2018 1:46 PM

All replies