Solved

Failed to rename and join to domain,using the VB script on  a windows 2008 server

Posted on 2009-07-08
7
950 Views
Last Modified: 2013-11-08
I failed to rename the windows 2008 server using the below script,please could you help me in resolving this

Background:

Building VM using SCVMM through template,Got a random name after the Build,so want to rename and domain join the server

Error Details:

Rename Failed Error:0
Existing script

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
 
Dim sCmpName
Dim sUser, sPassword, sDomain, sOU
 
sUser = "domain\username"
sPassword = "XXXXXXX"
sDomain = "domain"
 
 
sCmpName = InputBox("Enter the new computer name:", "Computer Name")
If sCmpName = "" Then
  Wscript.Echo "Exiting script."
  Wscript.Quit
End If
 
Dim oWMI, oCmp, oOS, sReturn
 
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
For Each oCmp in oWMI.InstancesOf("Win32_ComputerSystem")
  sReturn = oCmp.Rename(sCmpName)
  If sReturn <> 0 Then
    Wscript.Echo "Rename failed.  Error = " & Err.Number & _
      vbcrlf & "Exiting script."
  Else
    Wscript.Echo "Rename successful."
    sReturn = oCmp.JoinDomainOrWorkgroup(sDomain, sPassword, _
      sDomain & "\" & sUser,JOIN_DOMAIN+ACCT_CREATE)
    If sReturn <> 0 Then
      Wscript.Echo "Join domain failed.  Error = " & Err.Number & _
        vbcrlf & "Exiting script."
    Else
      Wscript.Echo "Join domain successful."
    End If
    Wscript.Echo "Rebooting computer..."
    For Each oOS in oWMI.InstancesOf("Win32_OperatingSystem")
      sReturn = oOS.Reboot
    Next
  End If
Next

Open in new window

0
Comment
Question by:rvsBhanu
[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
  • 3
7 Comments
 
LVL 31

Expert Comment

by:Henrik Johansson
ID: 24831721
The script/command neads to be run in a administrative context.
Start command prompt (or script) by right-click and choose 'Run as Administrator'.

Instead of vbscript, you can also use netdom command as below:
netdom renamecomputer %computername% /newname:<newname> /force /reboot

For joining the server to the domain, use the following netdom-command. /ou-parameter is only necessary if you want to put the computer object in another OU than the standard container.
netdom join %computername% /domain:domain.local /ou:OU-DN
0
 

Author Comment

by:rvsBhanu
ID: 24837228
Thanks you very munch for the information.Could you please provide me information how I can automatically run the Script in Runas Command I mean How Can I automate the script running in administrative mode.

0
 
LVL 31

Expert Comment

by:Henrik Johansson
ID: 24838468
'Run as administrator' is a part of UAC and shall not be possibly to automate access to admin approved mode as it's a native security feature that shall protect against execution of untrusted programs that changes system behavior (installation of trojans/viruses etc).

I remember I've seen some script somewhere that shall fire the UAC prompt for this kind of purpose. I shall see if I find it. Post me a reminder if I haven't posted back in a couple of days.
0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

Author Comment

by:rvsBhanu
ID: 24838540
Thanks a lot,will be wating for your post :)
0
 
LVL 31

Accepted Solution

by:
Henrik Johansson earned 500 total points
ID: 24887494
See the following link about UAC elevation sample
http://www.winhelponline.com/articles/185/1/VBScripts-and-UAC-elevation.html
0
 

Author Comment

by:rvsBhanu
ID: 24892496
Thanks for the link,I will try to use the tip mentioned in the link,Thank you once again.
0
 

Author Closing Comment

by:rvsBhanu
ID: 31601441
Thanks a lot
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

From Coral's  "So You Want To Play With Computers" Series A bit of background first, so this story will make a little sense. One day, probably because he needed a good laugh, Finagle hooked me up with a church to upgrade/run their Media Booth.…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
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…

751 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