jkrech17
asked on
Case Statement - VB/WMI Script / Need formatting help/advice
Hi,
I am trying to get a fully automated solution for deploying machines I manage in our department. I was going to try and write a WMI script that would get the MAC address, query the database, and name it appropriately. We use static machine names and ip addresses. I have virtually no experience in programming and would like some help/advice with the following:
Dim strMac
Dim NewComputerName
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("S elect * from Win32_NetworkAdapter",,48)
For Each objItem in colItems
If objitem.Manufacturer = "Broadcom" or objitem.Manufacturer = "Linksys" Then
strMac = objItem.MACAddress
End If
Next
***Can I put a case statement somewhere here where I can say if strMac = "blah" then NewComputerName = "blah"?***
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
err = ObjComputer.Rename(NewComu terName)
Wscript.Echo err
Next
I only have about 25 machiens or so and they are split up between three images, so there would only be a max of 10 choices for each image. Would this be the easiest way to name the machine to a predetermined static machine name?
Thanks in advance!
I am trying to get a fully automated solution for deploying machines I manage in our department. I was going to try and write a WMI script that would get the MAC address, query the database, and name it appropriately. We use static machine names and ip addresses. I have virtually no experience in programming and would like some help/advice with the following:
Dim strMac
Dim NewComputerName
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("S
For Each objItem in colItems
If objitem.Manufacturer = "Broadcom" or objitem.Manufacturer = "Linksys" Then
strMac = objItem.MACAddress
End If
Next
***Can I put a case statement somewhere here where I can say if strMac = "blah" then NewComputerName = "blah"?***
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
err = ObjComputer.Rename(NewComu
Wscript.Echo err
Next
I only have about 25 machiens or so and they are split up between three images, so there would only be a max of 10 choices for each image. Would this be the easiest way to name the machine to a predetermined static machine name?
Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.