I am trying to rename a bunch of workstations based on their serial number, and then a "D-" at the beginning if it is a workstation, and a "M-" if it is a notebook/laptop
For example a workstation would be renamed to D-SN12345 and a laptop would be renamed to M-SN12345
So far I have this:
CODE
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
strMsg = objItem.Caption
If strMsg = "Microsoft Windows XP Professional" Then
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//."
'WScript.Echo winmgmt1
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
for each SN in SNSet
If SN.SerialNumber = strComputer Then
MsgBox "Computer name already set! Name is: "& strComputer
Wscript.Quit
End If
If SN.SerialNumber = "" Then
MsgBox "Problem with computer naming!"
Wscript.Quit
End If
ErrCode = objComputer.Rename(SN.SerialNumber, strPassword, strUser)
If ErrCode = 0 Then
MsgBox "Computer renamed successfully to: "& SN.SerialNumber
End If
Next
End If
Next
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
strMsg = objItem.Caption
If strMsg = "Microsoft Windows XP Professional" Then
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//."
'WScript.Echo winmgmt1
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
for each SN in SNSet
If SN.SerialNumber = strComputer Then
MsgBox "Computer name already set! Name is: "& strComputer
Wscript.Quit
End If
If SN.SerialNumber = "" Then
MsgBox "Problem with computer naming!"
Wscript.Quit
End If
ErrCode = objComputer.Rename(SN.SerialNumber, strPassword, strUser)
If ErrCode = 0 Then
MsgBox "Computer renamed successfully to: "& SN.SerialNumber
End If
Next
End If
Next
This works well, but I am not sure how to go about determining if the computer is a workstation or a notebook, and then how to go about adding it to the beginning of the computer name
I did not write the script above, and I have very limited scripting knowledge
Any help would be GREATLY appreciated
