Here is an old version of a script I used use, I can't find a newer version
of it. I haven't used for ever but would get you started.
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array(".")
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS",
"WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)
For Each objItem In colItems
strBiosCharacteristics = Join(objItem.BiosCharacteristics, ",")
WScript.Echo "Computername: " & Left(objItem.Manufacturer,3) &
Left(objItem.SerialNumber,7)
usrComputername = Left(objItem.Manufacturer,3) &
Left(objItem.SerialNumber,7)
Next
Next
sNewName = usrComputername
Name = sNewName
Password = "password"
Username = "username"
Set objWMIService = GetObject("Winmgmts:root\cimv2")
' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in _
objWMIService.InstancesOf("Win32_ComputerSystem")
Return = objComputer.rename(Name)
If Return <> 0 Then
WScript.Echo "Rename failed. Error = " & Err.Number
Else
WScript.Echo "Rename succeeded." & _
" Reboot for new name to go into effect"
End If
Next
On Wed, Jan 20, 2016 at 6:31 AM, Beard, Julius <[email protected]>
wrote:
> Here’s a portion of a PowerShell script we use:
>
>
>
> $Serial = Get-WMIObject -Class Win32_Bios
>
> $CompSystem = Get-WMIObject -Class Win32_ComputerSystem
>
> $Model = $CompSystem.Model
>
> $Manufacturer = $Serial.Manufacturer
>
> if ($Manufacturer -like "*Dell*") {$Manufacturer="Dell"}
>
> if ($Manufacturer -like "*Hewlett*") {$Manufacturer="HP"}
>
> $ServiceTag = $Serial.SerialNumber
>
>
>
> #Renaming PC
>
> $CurrentName = $env:COMPUTERNAME
>
> if ($CurrentName -match $ServiceTag) {}
>
> else { Rename-Computer -computername $CurrentName -newname $ServiceTag }
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Gavin Wilby
> *Sent:* Wednesday, January 20, 2016 8:19 AM
> *To:* '[email protected]' <[email protected]>
> *Subject:* [NTSysADM] Rename PC batch/ powershell/ VB
>
>
>
> Hi All,
>
>
>
> I promise that I have Google searched this but unable to find a easy
> answer.
>
>
>
> I want a script to run after a machine is cloned that will rename the
> machine account to the serial number.
>
>
>
> I know I can get this by using *wmic bios get serialnumber*, ideally,
> prefixed with thin-, so thin-012345 for example.
>
>
>
> I can put the script to be called on the runonce reg key on next boot, but
> cannot get it formatted so it works correctly.
>
>
>
> Could anyone assist please?
>
>
>
> *Gavin Wilby*
>
> *IT Support Engineer*
>
>
>
> SMP Partners Ltd
>
> Clinch’s House, Lord Street,
>
> Douglas, Isle of Man IM99 1RZ
>
> Tel +44 1624 682214
>
> Mob +44 7624 480575
> *[email protected] <[email protected]>*
> www.smppartners.com
>
>
>
> A member of the SMP Partners Group of Companies
>
>
>
> SMP Partners Limited, SMP Trustees Limited and SMP Fund Services Limited
> are licensed by the Isle of Man Financial Services Authority. SMP
> Accounting & Tax Limited is a member of the ICAEW Practice Assurance Scheme.
>
> SMP Partners Limited registered in the Isle of Man, Company Registration
> No: 000908V
> Directors: M.W. Denton, M.J. Derbyshire, S.E McGowan, O. Peck, J.J. Scott,
> S.J. Turner
>
> SMP Trustees Limited registered in the Isle of Man, Company Registration
> No: 068396C
> Directors: A.C. Baggesen, J.M. Cubbon, M.W. Denton, K.M. Goldie, O Peck,
> J. Watterson
>
> SMP Fund Services Limited registered in the Isle of Man, Company
> Registration No: 120288C
> Directors: V. Campbell, R.K. Corkill, M.W. Denton, D.A. Manser, S.E
> McGowan, J.J. Scott
>
> SMP Accounting & Tax Limited registered in the Isle of Man, Company
> Registration No: 001316V
> Directors: I.F. Begley, A.J. Dowling, P. Duchars, J.J. Scott, S.J. Turner
>
> SMP Capital Markets Limited registered in the Isle of Man, Company
> Registration No: 002438V
> Directors: M.W. Denton, M.J. Derbyshire, D.F Hudson, S.E McGowan, O. Peck,
> J.J. Scott.
>
> SMP Partners Limited, SMP Trustees Limited, SMP Fund Services Limited, SMP
> Accounting & Tax Limited and SMP Capital Markets Limited are members of the
> SMP Partners Group of Companies.
>
>
>
> This email is confidential and is subject to disclaimers. Details can be
> found at: http://www.smppartners.com/disclaimer.html
> ______________________________________________________________________
> This email has been scanned by the Symantec Email Security.cloud service.
> For more information please visit http://www.symanteccloud.com
> ______________________________________________________________________
>