Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need assistance using wildcard within strComputer

Status
Not open for further replies.

kwondra34

IS-IT--Management
Apr 25, 2008
6
US
I am writing a script for a business. Just need some help. Basically I want to have the script run against multiple machines matching a certain department area.

The unc used in active directory is roomRoomNumber-comp#.

The code will be run through active directory so every computer in a sense will be local, even though the code wont work now since that machine is not avaliable from here I need to know that the wildcard will get all computers matching the first amount of characters.

For example, the code attached (targetComputer =) runs only on TRC210-10, however there are 30 computers in that room ranging from TRC210-01 to TRC210-30.

Each computer will run the script at login and it will integrate as though it were local through active directory.

Put in short, I need to make it so that my code uses TRC210-* (or some equivelent) and then runs the if then else statement against any computer that matches the beginning line "TRC210-"

Can you guys help me out a bit?

Kurt (Code below)

--------------

Dim objNetwork2

Set objNetwork = CreateObject("WScript.Network")
Set objNetwork2 = CreateObject("WScript.Network")
Set WshNetwork = CreateObject("WScript.Network")

strComputer = "TRC210-10"

If objNetwork2.Computername = UCase(strComputer) Then

' Mapping of Network Drives

objNetwork.MapNetworkDrive "X:" , "\\coho\groups"
objNetwork.MapNetworkDrive "Y:" , "\\coho\network"
objNetwork.MapNetworkDrive "Z:" , "\\coho\apps"

' Mapping of Remote Printers

WshNetwork.AddWindowsPrinterConnection "\\chinook\TC210_HP4250"
WshNetwork.AddWindowsPrinterConnection "\\chinook\TC218_HP2840"
WshNetwork.AddWindowsPrinterConnection "\\chinook\TC218_HP3500"

Else
WScript.Echo("Network Drives/Printers could not be assigned at this time")
End If
 
Also I tryed inStr but didnt get very far, I'm fairly bad at this so it would be nice to get some code please :)
 
Take a look at my FAQ faq329-4871. It might assist you some.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks alot to the both of you, I will look shortly mark

Huge, that is a good solution if the room name didnt change however the room name could be two or three characters, how do you think I should suppose.

TRC or LR are both room names which are in the UNC.

Thanks again in the future :)

Kurt
 
Code:
...
strPattern = UCase(Split(strComputer, "-")(0)) & "-"
If Left(UCase(objNetwork2.Computername), Len(strPattern)) = strPattern Then
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV... Thank you so so much. I know this is probably easy stuff for you but I was racking my brain.

Whats your paypal?? :)

Thanks a ton.

Kurt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top