Solved

can someone provide a script for the following

Posted on 2011-03-21
6
219 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
  • 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Synchronize a new Active Directory domain with an existing Office 365 tenant
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…
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 to another domain controller. Log onto the new domain controller with a user account t…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now