Solved

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

Posted on 2009-07-08
7
943 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
  • 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
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.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can’t delete a file 14 135
Do we need servers??? 5 186
Can't Decide: Office 365 Premium or Status Quo 7 92
shadow copy on 2012 OS server 3 48
Every once-in-a-while, when you try to add a XenServer host to the System Center Virtual Machine Manager console, it will generate a certificate error, and the XenServer host will not be added to Virtual Machine Manager: If you are experiencing t…
New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
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…

943 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

10 Experts available now in Live!

Get 1:1 Help Now