+ Post New Thread
Results 1 to 4 of 4
Windows 7 Thread, Script to change computer name/domain and language in Technical; Hi all, Im after a script that i can run after i imaged a computer that will allow me to ...
  1. #1
    newpersn's Avatar
    Join Date
    Nov 2010
    Location
    Gloucestershire
    Posts
    1,181
    Thank Post
    272
    Thanked 110 Times in 83 Posts
    Rep Power
    76

    Script to change computer name/domain and language

    Hi all,

    Im after a script that i can run after i imaged a computer that will allow me to change the computer name (and domain if i need to) and also let me change the computer language.

    Every time i re-image a computer it comes back in US even though i save it in Uk before sysprep

    Thanks

    Newperns

  2. #2
    jmcdermott's Avatar
    Join Date
    Feb 2008
    Location
    Cornwall
    Posts
    171
    Thank Post
    16
    Thanked 42 Times in 34 Posts
    Rep Power
    21
    We used this blog entry it might be some help to you.

    Network Management: Deploying Windows 7 to a domain

  3. #3

    Join Date
    Nov 2012
    Posts
    34
    Thank Post
    1
    Thanked 5 Times in 4 Posts
    Rep Power
    4
    Somthing like this should work

    Powershell:
    Code:
    param($p1)
    
    if(!$p1) {
         echo "Name Can Not Be NULL"
    } else {
         (Get-WmiObject win32_computersystem).rename($p1)
         Add-Computer -Credential MYDOMAIN\Admin -DomainName MYDOMAIN.local
         Set-WinSystemLocale en-GB
    }

  4. #4
    Duke5A's Avatar
    Join Date
    Jul 2010
    Posts
    793
    Thank Post
    80
    Thanked 130 Times in 113 Posts
    Blog Entries
    8
    Rep Power
    31
    I've got two separate scripts that will do this, so you need to splice them together.

    This one will join a domain:

    Code:
    Call DoSomething
    
    Sub DoSomething
    
    Dim strPassword
    Dim strDomain
    Dim strUser
    
    Const JOIN_DOMAIN             = 1
    Const ACCT_CREATE             = 2
    Const ACCT_DELETE             = 4
    Const WIN9X_UPGRADE           = 16
    Const DOMAIN_JOIN_IF_JOINED   = 32
    Const JOIN_UNSECURE           = 64
    Const MACHINE_PASSWORD_PASSED = 128
    Const DEFERRED_SPN_SET        = 256
    Const INSTALL_INVOCATION      = 262144
    
    strDomain   = "domainname"
    strUser     = "userwithaccesstojoindomain"
    
    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName
    
    Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
    
    Do
    	strPassword = InputBox("Enter password to join domain:", "Join to Domain", "password")
    	If strPassword = "" Then Exit Sub
    
    	ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, NULL, JOIN_DOMAIN + ACCT_CREATE)
    
    	If ReturnValue = 1326 Then
    		MsgBox "Logon failure: unknown username or bad password."
    	End If
    	
    	If ReturnValue <> 1326 Then Exit Do
    Loop
    	
    If ReturnValue = 5 Then
    	MsgBox "Access is denied.  Run from an elevated command prompt."
    	Exit Sub
    ElseIf ReturnValue = 87 Then
    	MsgBox "The parameter is incorrect."
    	Exit Sub
    ElseIf ReturnValue = 110 Then
    	MsgBox "The system cannot open the specified object."
    	Exit Sub
    ElseIf ReturnValue = 1323 Then
    	MsgBox "Unable to update password."
    	Exit Sub
    ElseIf ReturnValue = 1355 Then
    	MsgBox "The specified domain does not exist or could not be contacted."
    	Exit Sub
    ElseIf ReturnValue = 2224 Then
    	MsgBox "The account already exists."
    	Exit Sub
    ElseIf ReturnValue = 2691 Then
    	MsgBox "The machine is already joined to the domain."
    	Exit Sub
    ElseIf ReturnValue = 2692 Then
    	MsgBox "The machine is not currently joined to the domain."
    	Exit Sub
    End If
    
    If ReturnValue = 0 Then
    	If MsgBox("Domain joined successfully. Restart machine?", vbQuestion + vbYesNo) = vbYes Then
    		Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
    		For Each OpSys in OpSysSet
        			OpSys.Reboot()
    		Next
    		Else
    		'Just quit
    	End If
    End If
    
    End Sub
    This one will rename according serial number:

    Code:
    strDomain = "domainname"
    strUserName = "userwithaccess"
    strPassword = "password"
    
    Set objWMI = GetObject("winmgmts:").InstancesOf ("Win32_ComputerSystemProduct")
    
    For Each SystemItem in objWMI
    	strSerialNumber = SystemItem.IdentifyingNumber
    Next
    
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
    Set colComputers = objWMIService.ExecQuery ("Select Name from Win32_ComputerSystem")
    
    Do
    	For Each objComputer in colComputers
    		If objComputer.Name <> strSerialNumber Then
    		intErrorCode = objComputer.Rename(strSerialNumber, strPassword, strUserName)
    		End if
    	Next
    
    	Select Case intErrorCode
    		Case 0 strStatus = "Success"
    		Case 2 strStatus = "Missing OU"
    		Case 5 strStatus = "Access denied"
    		Case 53 strStatus = "Network path not found"
    		Case 87 strStatus = "Parameter incorrect"
    		Case 1326 strStatus = "Logon failure, user or pass"
    		Case 1355 strStatus = "Domain can not be contacted"
    		Case 1909 strStatus = "User account locked out"
    		Case 2224 strStatus = "Computer Account already exists"
    		Case 2691 strStatus = "Already joined"
    		Case Else strStatus = "UNKNOWN ERROR " & ReturnValue
    	End Select
    
    	Msgbox "Satus: " & 	strStatus
    	
    	If intErrorCode = 0 Then
    		Exit Do
    	Else
    		If MsgBox("Error encountered for " & strSerialNumber & ". Retry the rename?", vbQuestion + vbYesNo) = vbYes Then
    			'Do nothing
    		Else
    			Exit Do
    		End If
    	End If
    	
    Loop
    	
    If strStatus = "Success" Then
    	If MsgBox("Restart machine?", vbQuestion + vbYesNo) = vbYes Then
    		Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
    		For Each OpSys in OpSysSet
    			OpSys.Reboot()
    		Next
    	Else
    'Just quit
    	End If
    End If
    As far as your language settings are concerned it sounds like a goof in your sysprep answer file.

SHARE:
+ Post New Thread

Similar Threads

  1. script to change hostname and auto generate Hostname
    By vijay212004 in forum General Chat
    Replies: 6
    Last Post: 19th November 2013, 11:05 AM
  2. script to rename computer and join it to domain ...
    By RabbieBurns in forum Scripts
    Replies: 22
    Last Post: 2nd May 2013, 11:08 AM
  3. Replies: 0
    Last Post: 18th September 2012, 09:26 AM
  4. Change computer name and re join domain script?
    By agarabaghi in forum Windows 7
    Replies: 8
    Last Post: 12th June 2012, 03:11 PM
  5. script to change permission on folders for new domain
    By scottyses in forum Wireless Networks
    Replies: 1
    Last Post: 14th January 2008, 08:41 PM

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
  •