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

Home Forums Scripting General Scripting How to add and remove local user account for server not in the domain ?

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    albertwt
    Member
    #154838

    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:

    ‘ 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[/CODE]

    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”)[/CODE]

    they are all unable to add user itno the non domain joined server ?

    Any other help would be greatly appreciated.[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[/CODE]

    or using powershell:

    $Group = New-Object DirectoryServices.DirectoryEntry(“WinNT://192.168.1.156/Administrators”, “ITOperations”, “Password#123”)
    $Group.Add(“WinNT://192.168.1.156/ITOperations”)[/CODE]

    they are all unable to add user itno the non domain joined server ?

    Any other help would be greatly appreciated.[CODE]$Group = New-Object DirectoryServices.DirectoryEntry(“WinNT://192.168.1.156/Administrators”, “ITOperations”, “Password#123”)
    $Group.Add(“WinNT://192.168.1.156/ITOperations”)[/CODE]

    they are all unable to add user itno the non domain joined server ?

    Any other help would be greatly appreciated.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.