Solved

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

Posted on 2004-04-22
1
422 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
Comment Utility
Are you looking for something like this:

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now