A bit more challenging – Batch script to add domain user to local administrator group Windows 7

administratorbatch-filedns

I would like to write a script that will add a domain user to the local administrator group.
I already tried

NET LOCALGROUP Administrators "domain\domainuser" /ADD

but I get the Access Denied error.

The problem is that if I want to run it as domain user, it does not have local admin rights, and if as local admin, it does not have access to the domain names. (I don't want to use domain admin)

If I manually right click the computer icon, than manage, I type in the computer name/local admin user/pass, than in Local Users and Groups -> Groups folder I want to add user to Administrators, I am prompted to log in again. If I log in than with a domain user, it works.

My question is, if it is possible to do the same (or something similar) with batch script?

Best Answer

Maybe, from vbs

GetObject("WinNT://" + WScript.CreateObject("WScript.Network").ComputerName + "/Administrators").Add "WinNT://DomainName/UserName"
Related Topic