Solved

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

Posted on 2004-04-22
1
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

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