Create LocalAdmin User using VBS

Posted: June 28, 2019 in Bash Scripts, Scripting

Set Arg = WScript.Arguments

if Arg.count = 2 then
strUser = Arg(0) ‘Pass the username as parameter to the script
strPassword = Arg(1) ‘Pass the password as parameter to the script
end if

if IsEmpty(strUser) or IsNull(strUser) or strUser = “” or IsEmpty(strPassword) or IsNull(strPassword) or strPassword = “” then
strUser = “localadmin”
strPassword = “your_password_here”
end if

Set objWshNet = CreateObject(“WScript.Network”)
strComputer = objWshNet.ComputerName

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery (“SELECT Name,SID from Win32_Group where domain ='” & strcomputer & “‘”)
For Each objItem in colItems
sidAdmin = objItem.SID
if sidadmin = “S-1-5-32-544” then
strGroup = objItem.Name
end if
Next

Set colAccounts = GetObject(“WinNT://” & strComputer & “”)
Set objUser = colAccounts.Create(“user”, strUser)
objUser.SetPassword strpassword
objUser.SetInfo
Set objGroup = GetObject(“WinNT://” & strComputer & “/” & strGroup & “,group”)
objGroup.Add(objUser.ADsPath)

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.