Solved

can someone provide a script for the following

Posted on 2011-03-21
6
223 Views
Last Modified: 2012-05-11
we are looking for a script that will accomplish the following if possible:
1. add a user to the local administrator account
2. rename the machine
3. add computer to domain and reboot.

ideally if the script would prompt for step 1 and 2, so that we could enter the info. or if it can pull from a txt input file.

thx
0
Comment
Question by:siber1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
Joseph Moody earned 500 total points
ID: 35183272
Use restricted groups for to add the user to a security group.

Put both scripts on administrator desktop (on image if you want). Name one rename.vbs and the other domain.vbs.

Change the username/password/domain settings in the scripts.
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
 
strDomain = "Domain.local"
strUser = "username"
strPassword = "password"
 
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
 
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, NULL, JOIN_DOMAIN + ACCT_CREATE)

 rv = WshShell.run("shutdown -r -t 5", 1)

Open in new window

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

Name = InputBox("Enter the new computer name below and click OK to continue","Rename: Step 1")

Username = "administrator"
Password = "something"

Set objWMIService = GetObject("Winmgmts:root\cimv2")

' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem")
        Return = objComputer.rename(Name,Password,User)
        If Return <> 0 Then
           WScript.Echo "Rename failed. Error = " & Err.Number
        End If
Next

WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\JoinDomain", """C:\Documents and Settings\Administrator\Desktop\domain.vbs""", "REG_SZ"
 rv = WshShell.run("shutdown -r -t 5", 1)

Open in new window

0
 
LVL 22

Expert Comment

by:Joseph Moody
ID: 35183274
Bottom script is rename.vbs
0
 

Author Comment

by:siber1
ID: 35183315
thx.  
rather than user restricted groups via GPO or local policy, is there a way to have a script prompt for the domian user name and add this to the LA group on the computer?
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 22

Expert Comment

by:Joseph Moody
ID: 35183339
Probably. I don't have one in my bag of scripts though.
0
 

Author Comment

by:siber1
ID: 35191020
Hi J,
I just tested the rename script and get the error message: "rename failed"
0
 
LVL 22

Expert Comment

by:Joseph Moody
ID: 35191037
Upload your script here so that I can look it over.
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question