Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-08
7
Medium Priority
?
956 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

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

Accepted Solution

by:
Henrik Johansson earned 1500 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
Suggested Courses

722 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