Solved

Case Statement - VB/WMI Script / Need formatting help/advice

Posted on 2004-04-22
1
423 Views
Last Modified: 2013-12-03
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("Select * 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=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
    err = ObjComputer.Rename(NewComuterName)
    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!


0
Comment
Question by:jkrech17
1 Comment
 
LVL 8

Accepted Solution

by:
KerryG earned 500 total points
ID: 10891175
Are you looking for something like this:

select case strMac
    case "0000aaaabb"
      NewComputerName = "machine1"
    case "000bbbbbbb"
      NewComputerName = "machine2"
end select
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question