Jump to content

Recommended Posts

Posted

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

Posted

Somthing like this should work

 

Powershell:

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
}

Posted

I've got two separate scripts that will do this, so you need to splice them together.

 

This one will join a domain:

 

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:

 

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...