Solved

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

Posted on 2009-07-08
7
941 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
Comment Utility
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
Comment Utility
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
Comment Utility
'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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Accepted Solution

by:
Henrik Johansson earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot
0

Featured Post

Why do Marketing keep bothering you?

Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

Join & Write a Comment

Introduction RemoteFX is already in use today, but you're probably not aware of it.  With the advent of Windows 2012 and Windows 8, RDP has gotten a whole lot better due to the fact that RDP now uses even more RemoteFX technologies to make desktop …
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 push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…

763 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

6 Experts available now in Live!

Get 1:1 Help Now