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

Check multiple groups and map the drive? 3

Status
Not open for further replies.

ColdFlame

Technical User
Jul 24, 2007
48
CA
Hey there,

I'm trying to re-write my login scripts and amalgamate my 4 scripts into one login script. In doing so, there is tons of redundancy that I want to eliminate.

My main problem at the moment is trying to do something along these lines, but I'm not sure if it can be done in VBS...

If InGroup ("Accounting", "PayrollGroup", "HRGroup") Then
MapDrive "N:", "\\server\Acct"
End If

Is that right? I have seen, though now can't find, an example that did this:

If InGroup ("Accounting", "PayrollGroup", "HRGroup",0) Then
MapDrive "N:", "\\server\Acct"
End If

Essentially I want the script to check that particular user if they're in any of the aforementioned groups, and if so, then map that drive. I really don't want to have three if statements just to check those three groups.

TIA!

Jeremy
 
Yeah, MarkdMac's Login Script FAQ is the defacto learning tool. I memorized it a while back because it shows you how to do so many things.

You can ask questions of me anytime...I'm glad to help.
 
Yeah, Jeremy will have to go to you Bryce since he said that vbscript is not cool.....

smileeek.gif


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.
 
Just for the record, my FAQ did specifically point out the case sensitivity of the groups and I recommend always forcing comparrison in either all upper case or all lower case just to avoid additional work.

Case in point the above testing and failures. Like you guys have started I learned through a lot of trial and error and try to share in my FAQs what I have found to be best practices over the years.

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.
 
Markdmac,

Just out of curiousity, I did see your script pointing out the Ucase portion, etc..., but my question is this:

Does the UCase force the groupname in the brackets to upper case for comparison, and thus, it has to match in AD? Or, can I leave my groups in AD as "5th Floor" and then in the script write them in as "5TH FLOOR" using the Ucase statement?

Sorry, but I'm just a little unclear on that... Thanks in advance.

Jeremy
 
CF,

The UCASE built in function merely converts all characters within the parentheses to upper case.

Ucase(variable) = VARIABLE

The point is to match the case on every character from your script to the corresponding AD group.
 
Oh ok... Thanks as usual Brycspain.

I guess I'll have to set to it renaming my AD Groups then at some point if I'm to do that. Or, at least, create a standardized case convention in my AD groups. I'm very standardized, however two other IT members here are not and don't really give two craps what things look like.

I hate all Uppercase... I don't want my groups to seem angry at me all the time! =) *laughs*
 
ColdFlame you are missing the mark on this. The use of UCase or LCase negates the need to change your groups in AD.

Here is an example:

Suppose you have a group name in AD as Sales and Marketing

If you were to compare this in the Select Case like this:

Select Case Group
Case "Sales and marketing"

Then the comparison would fail because the M in Marketing is not upper case.

To look at it in an equation:

Group = "Sales and Marketing"
Group <> "Sales and marketing"

To avoid this we force the comparison to all upper case for EACH side of the equation.

Group = UCase("Sales and Marketing")
Group = "SALES AND MARKETING"

So you see, the group name from AD is in mixed case, but we set the variable in the script to be equal to the uppercase value of that string. Then in the Case section of our Select statement we give all upper case values to compare against.


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 Mark, thats why I could never make sense of why to use Ucase for group comparisons. In other words, if you force the comparison using Ucase, it doesn't matter what case the AD group is using. You can have a star.
 
Ahh, well now that makes sense to me. I understand now. Thanks Mark! =)
 
I have a slight problem with a portion of my script I have discovered.

'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next


This also disconnects my users K:\ drive (which is their home directory). The K:\ drive is mapped via AD under their Profile tab. Is there a way for it to NOT disconnect that K:\ drive short of putting it in this login script?

Thanks in advance as usual!

Jeremy
 
Unfortunately, if you map the home folders within the user's profile you can't use the disconnect mapped drives sub.


Now, if you map the home folders using your login script then you can revert back to using the sub. Any reason you can't do that?
 
sorry, I have nothing of real value to add to this conversation, but did anyone else start laughing almost uncontrollably from this part:
I hate all Uppercase... I don't want my groups to seem angry at me all the time! =)
sigh...my wife things I'm a total geek now
 
Actually I got a good chuckle out of that too, of course my wife has known for years that I am a total geek. Glad you came out of the closet!

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.
 
If nothing else, at least I'm able to provide a bit of comic relief to the boards at times... =)

Cheers guys.

Jeremy

PS: Unclerico; your wife already knew you were a geek, you just reaffirmed it for her. *grins*
 
There is enough anger in the world...you don't have to put up with it from your groups =) I say make them all lowercase.
 
Brycspain; there sure is, and I won't put up with it from my groups! Lowercase for life! *laughs*

Somewhat off-topic for this, but I have another question (go figure? :p)

We need to create a folder on all of our users harddrives (C:\DB) and give Domain Users modify rights to it.

Is there a way to script this? Whether it be a batch file or whatever, I really don't want to run around to all ~250 machines to do it if not necessary. Your help, as always, is appreciated! =) My users are all just normal users w/o any power or administrative privileges (most anyway)...

Thanks again,

Jeremy
 
How are you running your login script? Through a GPO? If you run your script through a GPO it will have complete control over your user's PCs no matter who logs into them. This would be very easy to script using your login script.


This will create the folder if it doesn't already exist.
Code:
objFolder = "c:\db"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FolderExists(objFolder) Then
   objFSO.CreateFolder(objFolder)
Else
End If

You will then need to use calcs to set the permissions on it like this:

No sure about the syntax to add domain users and I don't have time to look it up right now however, this should get you started.


Code:
If objFSO.FolderExists(objFolder) Then
Set oShell = CreateObject("Wscript.Shell")
objShell.Run("%COMSPEC% /c Echo Y| cacls " & _ 
objFolder & " /t /e /c /g "& [b]"Domain User"[/b] & ":c /r ", 2, True)
End If
 
First, try creating the directory on a test pc using your script and note the default permissions. If they aren't adequate for your needs then you can use the following code to add domain users with modify permissions.
Here is the code however, you will have to look up calcs.exe and find the right syntax. I used to know how to work it but it's been a while:

Code:
If objFSO.FolderExists(objFolder) Then
Set oShell = CreateObject("Wscript.Shell")
objShell.Run("%COMSPEC% /c Echo Y| cacls " & _ 
objFolder & " /t /e /c /g ""Domain Users"" :c /r ", 2, True)
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top