Solved

can someone provide a script for the following

Posted on 2011-03-21
6
222 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

733 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