Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

can someone provide a script for the following

Posted on 2011-03-21
6
Medium Priority
?
225 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 2000 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

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 process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

610 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