Solved

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

Posted on 2009-07-08
7
946 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Problem to setup GUI 11 46
Word 2016 Installation Problem on Terminal Server 9 39
Erasing Folder Windows 2008R2 8 22
Run Windows Server from USB 2 17
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article explains how to install and use the NTBackup utility that comes with Windows Server.
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…

828 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