+ Post New Thread
Results 1 to 1 of 1
Scripts Thread, Rename a computer while on the domain in Coding and Web Development; Here is a script I put together for some remote computer renaming that I need to do - don't bash ...
  1. #1

    Join Date
    Jan 2010
    Posts
    7
    Thank Post
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    0

    Rename a computer while on the domain

    Here is a script I put together for some remote computer renaming that I need to do - don't bash the coding skills I'm a Systems Engineer by trade

    Code:
    '#############
    '# Get Host  #
    '#############
    On error resume next
    strComputer = WScript.arguments.item(0)
    
    if strComputer = "" then
    strComputer  = InputBox( "Name of computer to rename" )
    if strComputer = "" then
    	wscript.echo "No computer name suppled"	
    	wscript.quit
    end if
    end if
    
    '##########
    '# Ping   #
    '##########
    
        Dim colPingResults, objPingResult, strQuery
    
        ' Define the WMI query
        strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & strcomputer & "'"
    
        ' Run the WMI query
        Set colPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery( strQuery )
    
        For Each objPingResult In colPingResults
            If Not IsObject( objPingResult ) Then
                Ping = False
            ElseIf objPingResult.StatusCode = 0 Then
                Ping = True
            Else	
    	    Wscript.Echo "Computer COULD NOT be contacted - Exiting"
    	    wscript.quit
                Ping = False
            End If
        Next
    
        Set colPingResults = Nothing
    
    '##########
    '# Get SN #
    '##########
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colBIOS = objWMIService.ExecQuery _
        ("Select * from Win32_BIOS")
    For each objBIOS in colBIOS
    strSerialNumber = trim(objBIOS.SerialNumber)
    Next
    
    '##############
    '# Get Info   #
    '##############
    strSerialPrompt = "Hint: SN is " & strSerialNumber
    
    if strSerialNumber = "N/A" then
    strSerialPrompt = "Serial Number Not Available"
    strSerialNumber = ""
    end if
    
    if strSerialNumber = "" then
    strSerialPrompt = "Serial Number Not Available"
    strSerialNumber = ""
    end if
    
    strNewComputer  = InputBox( "Enter new computer name - " & strSerialPrompt, "New Computer", "???-??-" & strSerialNumber) 
    if strNewComputer = "" then
    	wscript.echo "No new computername suppled"	
    	wscript.quit
    end if
    strDomainUser   = InputBox( "Enter username in this format: domain\username" )   
    if strDomainUser = "" then
    	wscript.echo "No Domain User suppled"	
    	wscript.quit
    end if
    strDomainPasswd = InputBox( "Enter account password" )
    if strDomainPasswd = "" then
    	wscript.echo "No Domain Password suppled"	
    	wscript.quit
    end if
    
    '#############
    '# Connect   #
    '#############
    set objWMILocator = CreateObject("WbemScripting.SWbemLocator")
    objWMILocator.Security_.AuthenticationLevel = 6
    set objWMIComputer = objWMILocator.ConnectServer(strComputer,  _
               		                         "root\cimv2", _
                                                      strDomainUser, _
                                                      strDomainPasswd)
    set objWMIComputerSystem = objWMIComputer.Get( _
                                   "Win32_ComputerSystem.Name='" & _
                                   strComputer & "'")
    '##########
    '# Rename #
    '##########
    
    rc = objWMIComputerSystem.Rename(strNewComputer, _
                                     strDomainPasswd, _
                                     strDomainUser)
    if rc <> 0 then
        WScript.Echo "Rename failed with error: " & rc
    else
        WScript.Echo "Successfully renamed " & strComputer & " to " & _
                     strNewComputer
    end if
    
    '##########
    '# Reboot?#
    '##########
    intAnswer = _
        Msgbox("Do you want to reboot the remote computer?", _
            vbYesNo, "Reboot")
    
    If intAnswer = vbYes Then
        Set objOSSet = GetObject("winmgmts:{(RemoteShutdown)}//" & strComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
    
        For each objOS in objOSSet
    	objOS.Reboot()
        Next
    
    Else
     'No
    End If

  2. Thanks to msnriggs from:

    lionsl2005 (20th January 2010)

SHARE:
+ Post New Thread

Similar Threads

  1. script to rename computer and join it to domain ...
    By RabbieBurns in forum Scripts
    Replies: 22
    Last Post: 2nd May 2013, 11:08 AM
  2. [Fog] Rename w/ serial # and join domain
    By Onslow in forum O/S Deployment
    Replies: 15
    Last Post: 20th July 2010, 09:42 AM
  3. Rename My Computer Via Registry
    By FN-GM in forum Windows 7
    Replies: 10
    Last Post: 14th September 2009, 08:43 PM
  4. Domain Rename = Anyone done it ?
    By pooley in forum Windows
    Replies: 3
    Last Post: 25th May 2006, 12:57 PM
  5. Replies: 13
    Last Post: 20th July 2005, 01:47 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •