Solved

can someone provide a script for the following

Posted on 2011-03-21
6
217 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 21

Accepted Solution

by:
Joseph Moody earned 500 total points
Comment Utility
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 21

Expert Comment

by:Joseph Moody
Comment Utility
Bottom script is rename.vbs
0
 

Author Comment

by:siber1
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 21

Expert Comment

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

Author Comment

by:siber1
Comment Utility
Hi J,
I just tested the rename script and get the error message: "rename failed"
0
 
LVL 21

Expert Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

771 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

12 Experts available now in Live!

Get 1:1 Help Now