Announcement

Collapse
No announcement yet.

How to add and remove local user account for server not in the domain ?

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

  • How to add and remove local user account for server not in the domain ?

    Hi,

    Is there any way to create a custom user as local admin of server that is not joined to the domain ?

    I tried the following script but it failed in line SetInfo on VBScript:

    Code:
    ' get target machine name and password 
    ' from command line arguments 
    strServer = "DMZWebServer-VM" 'wscript.arguments(0) 
    strPwd = "Password#" 'wscript.arguments(1) 
    strUser = "ITOperations" 
     
    ' connect to target machine and  
    ' create new user 
    Set oServer = GetObject ("WinNT://" & strServer) 
    Set oUser = oServer.Create ("user", strUser) 
    oUser.SetPassword strPwd 
    oUser.SetInfo 
     
    ' add new user to 'Administrators' group 
    Set Group = GetObject("WinNT://" & strServer & "/administrators,group") 
    Group.Add(oUser.ADsPath) 
    Group.Setinfo 
     
    ' release objects 
    Set oServer = nothing 
    Set oUser = nothing 
    Set group= nothing
    or using powershell:

    Code:
    $Group = New-Object DirectoryServices.DirectoryEntry("WinNT://192.168.1.156/Administrators", "ITOperations", "Password#123")
    $Group.Add("WinNT://192.168.1.156/ITOperations")
    they are all unable to add user itno the non domain joined server ?

    Any other help would be greatly appreciated.

  • #2
    Re: How to add and remove local user account for server not in the domain ?

    I've used the following script that I got from technet script repo that worked for me:

    Code:
    on error resume next
    
    Set objNet = WScript.CreateObject( "WScript.Network" )
    Const FOR_READING = 1    
    strFilename = "c:\scripts\workstations.txt"    
    strUser = "testuser"    
    Set objFSO = CreateObject("Scripting.FileSystemObject")    
    Set objTextStream = objFSO.OpenTextFile(strFilename, FOR_READING)        
    
    Do Until objTextStream.AtEndOfStream   
       
         ' Create user      
         strComputer = objTextStream.ReadLine      
         Set colAccounts = GetObject("WinNT://" & strComputer & "")      
         Set objUser = colAccounts.Create("user", strUser)      
         objUser.SetPassword "ENTERPASSWORDHERE"      
         objUser.SetInfo      
         Wscript.Echo "Added user " & strUser & " to " & strComputer    
       
         ' add user to admin group      
         Set objLocalUser = GetObject("WinNT://" & strComputer & "/" & strUser)      
         Set objLocalAdmGroup = GetObject("WinNT://" & strComputer & "/Administrators,group") 
        
         objLocalAdmGroup.Add(objLocalUser.AdsPath)      
         Wscript.Echo "Added user " & strUser & " to " & strComputer & "'s local admin group"  
    
    Loop
    Last edited by falbanese; 30th May 2011, 17:36.

    Comment

    Working...
    X