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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Wildcards

Status
Not open for further replies.

MojoZig

Technical User
Sep 27, 2005
61
US
I am creating a script to log a few network drives. I have one drive that all the Database users get. All the groups for Database users begin with "COO_DB_"

Is there a wildcard I can use for all groups that begin with COO_DB_ to get this drive mapped or would I have to list all of the groups? Here's the code with about 50 other groups cut out for brevity.
======================
Case "COO_DB_AP_Administration, COO_DB_AP_Airport, COO_DB_Auditor, COO_DB_BLD_Administration, COO_DB_BLD_Building"
objNetwork.MapNetworkDrive "X:", "\\server\drive\City_Databases"
======================
I guess I could create a group and nest all the database groups in one and just put that in place of the others ...
Thoughts?
I appreciate your time!

Tommy
 
If Left(yourVariable, 7) = "COO_DB_" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Is this what you mean? See below:

=======================
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

Select Case strGroupName

If Left(strGroupName, 7) = "COO_DB_" Then objNetwork.MapNetworkDrive "X:", "\\server\drive\City_Databases"
=========================

Do I leave out the "Case"? or should it be:

Case If Left(strGroupName, 7) = "COO_DB_" Then
(Then the map drive line)

I appreciate your assistance! I'll try it out as well ... will let you know!

Tommy
 
Also, would I then need to put an "End If" after the drive map line? Please excuse my ignorance! VBScript, or programming in general isn't my bag but have been really liking working on this login script!

Tommy
 
Either:
Select Case Left(strGroupName, 7)
Case "COO_DB_"
objNetwork.MapNetworkDrive "X:", "\\server\drive\City_Databases"
Case ...
End Select
Or:
If Left(strGroupName, 7) = "COO_DB_" Then
objNetwork.MapNetworkDrive "X:", "\\server\drive\City_Databases"
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yeah, I don't know what I'm doing wrong ...

when I put:
============
Case "COO_DB_AP_Administration"
objNetwork.MapNetworkDrive "X:", "\\chldept\drive\City_Databases"
=============

The drive maps, which tells me the permissions are correct, the path is correct and that I am a part of the COO_DB_ group for the Airport, but I tried both suggestions above and it won't map ...

Ahhhh ... I just made it work! You were completly correct, only I was adding it in the wrong spot I guess. I put it above all the department mapped drives that are done by Case and then the group name and it worked. (Like my technical script talk?) :eek:)

It works like this:
============================
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

' This is for the City_Database Drive
If Left(strGroupName, 7) = "COO_DB_" Then
objNetwork.MapNetworkDrive "X:", "\\server\drive\City_Databases"

End If

Select Case strGroupName


' These are for the Deparment's Main S: Drive Share

Case "COO_AP_Airport"
objNetwork.MapNetworkDrive "S:", "\\server\Drive\Airport"
objNetwork.AddWindowsPrinterConnection "\\server\Airport HP LaserJet 4000", "Airport HP LaserJet 4000"

Case "COO_Auditor"
objNetwork.MapNetworkDrive "S:", "\\server\Drive\Auditor"

Case "COO_BLD_Building"
objNetwork.MapNetworkDrive "S:", "\\server\Drive\Building"
objNetwork.AddWindowsPrinterConnection "\\server\Building Inspectors LaserJet 2200", "Building Inspectors LaserJet 2200"
objNetwork.AddWindowsPrinterConnection "\\server\Building LaserJet 4500", "Building LaserJet 4500"
=============================
and then so on and so on through each departments groups for their department drives and printers.

PHV, you rock! Thanks for your very quick response! I got the answer in less than 5 minutes of creating my account and posting my question!

Man, you have got to get away from your computer!!! :eek:) JK

Thanks again and I greatly appreciate your time!

Tommy Thomas,
MCP, Net+, Security+, C|EH



 
For anyone looking for a good script to map User Home directories and other specific drives and installs Printers via the user's group membership here's a script from Microsoft and few other places. I had issues with the orginal M$ script but finally got it working. Here is the final script in a nutshell:

============================

' VB Script Document

'Maps the user's home drive and matches their login name to their home folder

Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
on error resume next
'WShNetwork.RemoveNetworkDrive "H:", True, True
WshNetwork.MapNetworkDrive "H:","\\Server\drive\" & WshNetwork.UserName


'These next three lines map the CityShare
on error resume next
'WShNetwork.RemoveNetworkDrive "U:", True, True
WshNetwork.MapNetworkDrive "U:","\\Server\drive\City_Share"


On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

'These next lines map the Central Services Aficio Copiers
objNetwork.AddWindowsPrinterConnection "\\Server\CMO Aficio 2060", "CMO Aficio 2060"
objNetwork.AddWindowsPrinterConnection "\\Server\CMO Aficio 2232C", "CMO Aficio 2232C"
objNetwork.AddWindowsPrinterConnection "\\Server\Purchasing Aficio 2060", "Purchasing Aficio 2060"
objNetwork.AddWindowsPrinterConnection "\\Server\Purchasing Aficio 2232C", "Purchasing Aficio 2232C"

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

' This is for the City_Database Drive, reads the first seven characters of the database groups and adds the x drive, thanks to PHV.

If Left(strGroupName, 7) = "COO_DB_" Then
objNetwork.MapNetworkDrive "X:", "\\Server\drive\City_Databases"

End If

Select Case strGroupName


' These are for the Department's Main S: Drive Share

Case "COO_AP_Airport"
objNetwork.MapNetworkDrive "S:", "\\Server\Drive\Airport"
objNetwork.AddWindowsPrinterConnection "\\Server\Airport HP LaserJet 4000", "Airport HP LaserJet 4000"

Case "COO_Auditor"
objNetwork.MapNetworkDrive "S:", "\\Server\Drive\Auditor"

Case "COO_BLD_Building"
objNetwork.MapNetworkDrive "S:", "\\Server\Drive\Building"
objNetwork.AddWindowsPrinterConnection "\\Server\Building Inspectors LaserJet 2200", "Building Inspectors LaserJet 2200"
objNetwork.AddWindowsPrinterConnection "\\Server\Building LaserJet 4500", "Building LaserJet 4500"
objNetwork.AddWindowsPrinterConnection "\\Server\Zoning Code Enforcement 2500C", "Zoning Code Enforcement 2500C"
objNetwork.AddWindowsPrinterConnection "\\Server\Zoning LaserJet 4200", "Zoning LaserJet 4200"


' These are for the Department's Secondary T: Drive Share

Case "COO_AP_Administration"
objNetwork.MapNetworkDrive "T:", "\\Server\Drive\Airport\COO_AP_Administration"

Case "Department Group Name"
objNetwork.MapNetworkDrive "T:", "\\Server\Drive\Department_Share"



' Extra Drive letter code.

' Case "COO_XX_XXXXX"
'objNetwork.MapNetworkDrive "T:", "\\server\Drive\XXXXXXXX"


End Select
Next
=================================

Let me know if you find any errors that need correcting or any suggestions since I'm not the best programmer ... :eek:)

Sincerely,
Tommy
 
if you bound to the user using WinNT provider then you wouldnt need to bind to each group the user is a member of to find out the groups WinNT friendly name.
i would suggest m$ need to re think what they post on logonscripts! try running that amount of ad binds over a network connection with high latency!!!

anyway, logonscripts are a true art form.
for me the fundamental goal of any logonscript should be that once written you should never need to change the logonscript ever again. to this end the LS should not contain any static references to folder, files, shares, servers, groupnames, printers etc etc.
 
I wish I had the knowledge to shorten the whole script but unfortunately programming is really not my bag ... I know this since I have a slight understanding as to what you are talking about when you say:

"if you bound to the user using WinNT provider then you wouldnt need to bind to each group the user is a member of to find out the groups WinNT friendly name."

When I say slight, I mean that I know what binding is ... somewhat! (That's when you eat a lot of cheese right?) JK :eek:) Since I got the script from two or three different places, I'm kind of stuck with the one script for now!

Here's a challenge: Anybody want to rewrite the script, just post it here and I'll test it in my test directory ... :eek:)

Is there a limit on the number of lines a script should be for logon purposes? I have 70 department and division groups so you can see how that will make the script pretty long! The script doesn't seem to take that long out of production, but when it goes into production there will only be about 500 users affected.

Tommy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top