Add domain user to administrators group on remote machine (VBScript)
We have a support team that they need to our assistance about adding their accounts to local administrators group of some computers. My colleagues have to open “Computer Management”, connect to remote computer and add the user to the group. I don’t like this process.
The below script helps my colleagues, maybe useful for you as well:
'Version 1.0
'Written by Davoud Teimouri
Option Explicit
On Error Resume Next
Dim strComputer
Dim strUser
Dim objGroup
Dim ObjUser
strComputer = Inputbox ("Please enter the computer name (Without domain name):")
strUser= Inputbox ("Please enter the user name:")
strComputer=strComputer & ".Your Domain"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://Your Domain/" & strUser & ",user")
If Ping(strComputer) Then
Err.Description=""
Else
Err.Description=" The target is not reachable."
End If
If Err=0 Then
objGroup.Add(objUser.ADsPath)
Msgbox (strUser & " has been added to administrators group of " & strComputer)
Else
Err.Description=" Please check the username."
DisplayErrorInfo
End If
Sub DisplayErrorInfo
WScript.Echo "An error is occurred." & Err.Description
Err.Clear
End Sub
Function Ping(strHost)
Dim oPing, oRetStatus, bReturn
Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address='" & strHost & "'")
For Each oRetStatus In oPing
If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
bReturn = False
Else
bReturn = True
End If
Set oRetStatus = Nothing
Next
Set oPing = Nothing
Ping = bReturn
End Function
Further Reading
Run ESXi Commands Via PowerShell And SSH
it gives error, please check your username
You should change something on script such as “Your Domain” with domain name. Did you change them?