locked
VBScript Logon script Case AND RRS feed

  • Question

  • I am trying to get CASE to work with AND condition and maybe I just need to do IF THEN ELSE instead but here is what I am trying to accomplish or maybe I am missing something:

    Run script User must be part of the groups to map the drive. Problem I am having is in a CASE where an end user is in multiple groups. I want a user to be EXACTLY in the groups specified NOT one or the other. If they are not in both groups then it doesn't need to map them.

    On Error Resume Next

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

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

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

        Select Case strGroupName

    'Manufacturering Group
            Case "Manufacturing Users"
                objNetwork.MapNetworkDrive "p:", "\\data\share"

    'Network Services user group
            Case "Employees A-K"AND"ACL Admins"
                objNetwork.MapNetworkDrive "I:", "\\data\share"
                objNetwork.MapNetworkDrive "H:", "\\home\userdata\"

        End Select
    Next

    Wednesday, April 16, 2014 7:44 PM

Answers

  • I have been an Admin/Engineer since 1999.

    I would have used GPO if management would approve. They were burned by a previous engineer that caused a significant amount of issues using GPO. Now everything done has to be approved by a committee of non-I.T. professionals. The mention of GP and they stop the process and panic.

    That is why I brought this topic up. I would have LOVED to use GPP since it is so much easier then having to figure out and learn VBScript... I'd rather do it in batch files but that isn't an option.

    Why is it that assistance on Technet is almost always:

    No you are doing it wrong. Why would you do something like that?

    Instead of:

    I understand you have a situation then my suggestion would be X. If its not going to work then just say it.

    • Marked as answer by Brad_Voris Thursday, April 17, 2014 12:57 PM
    Thursday, April 17, 2014 12:57 PM

All replies

  • The first step you should use to troubleshoot is to remove the line On Error Resume Next from the top of the script. That line will hide all errors and make things very hard to troubleshoot. (Do not use that line of code unless you understand exactly what it does.)

    On the other hand, you really should consider using group policy preferences to map drives. In this way you don't even have to worry about using a script at all.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 16, 2014 7:50 PM
  • Group Policy is not an option.

    Your suggestion did help:

    So now I am one step closer but how do I suppress this error without causing the condition?


    • Edited by Brad_Voris Wednesday, April 16, 2014 7:57 PM
    Wednesday, April 16, 2014 7:55 PM
  • Why isn't Group Policy an option? That's by far the best way to solve this problem.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 16, 2014 8:07 PM
  • Management and prior GP configuration issues. GPP would be ideal but not in this situation.

    VBS will help me consolidate some 350+ batch logon scripts to about 10 logon scripts.(Possibly even less)

    Wednesday, April 16, 2014 8:13 PM
  • What you're asking is not supported by the Select Case statement in VBScript. The Case expression in Select Case supports a list, but it doesn't mean "and" (it means "any of"). So really your script would need to be redesigned if you want "user must be member of both groups to get this drive mapping."

    So you're going to need to do your homework on how to accomplish this. Group Policy Preferences is a better solution and doesn't require programming knowledge/experience.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 16, 2014 8:41 PM
  • LOL You could have told me that on your first reply.

    Looks like I will re-write the script.

    Again I agree GPP would be ideal just not in this situation.

    Wednesday, April 16, 2014 8:43 PM
  • One of the purposes of GPP is so that we don't have to write code to map drives, so it seems to me it would be ideal in your situation. It's always better if you don't have to reinvent the wheel.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 16, 2014 8:57 PM
  • I can never figure out why new Admins insist on using old NT4 methods when the Windows 2008 and later methods are so powerful and easy to use.  Logon scripts are almost entirely unnecessary.

    So many Admins are afraid of GP. Many became fearful because they didn't realize how nearly instantaneous GP is and made bad changes that brought the network down.

    GP is faster and safer than a logon script.  Changes can be pushed even while a user is logged in.

    Printer connections can be done extremely easily even on older XP systems.

    IN GP create a script to map a printer and set the filter on the policy that contains the logon script. You can use a different GPO for each printer and use one or more filtering groups.  To combine filters just add the two groups to a third group and use that as your filter.


    ¯\_(ツ)_/¯

    Wednesday, April 16, 2014 9:49 PM
  • I have been an Admin/Engineer since 1999.

    I would have used GPO if management would approve. They were burned by a previous engineer that caused a significant amount of issues using GPO. Now everything done has to be approved by a committee of non-I.T. professionals. The mention of GP and they stop the process and panic.

    That is why I brought this topic up. I would have LOVED to use GPP since it is so much easier then having to figure out and learn VBScript... I'd rather do it in batch files but that isn't an option.

    Why is it that assistance on Technet is almost always:

    No you are doing it wrong. Why would you do something like that?

    Instead of:

    I understand you have a situation then my suggestion would be X. If its not going to work then just say it.

    • Marked as answer by Brad_Voris Thursday, April 17, 2014 12:57 PM
    Thursday, April 17, 2014 12:57 PM
  • I would suggest putting that information in your original post then.

    If you know for a fact that you're looking for a hacky workaround, you should state that right up front. Also, remember that we can't test hacky workarounds in your environment, so we're not going to be able to hand you something that works without adjustment.


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    Thursday, April 17, 2014 1:12 PM
  • If you are using a logon script you are using GP.  All you need to do is add a Security Group filter to the GP.  Nothing can go wrong by doing this.

    What you are trying to do is far more disruptive than any GP filter can be.

    You are free to do anything in any way you choose.  When you ask a question and post script that shows a very limited knowledge of scripting and of Active Directory and modern Windows (since W2K so it is now almost 15 years old) then it is necessary to try and tell you that you are doing things in a very counterproductive way.

    You should make a presentation to your management on how AD and GP work in Windows 2000 and later systems.  It might be worthwhile to contract a consultant to come in and give the presentation.  "Policy" based administration is just what managers want.  What they don't want is a lot of tech talk.  GP is targeted at managers.  "Policy" is a management term.


    ¯\_(ツ)_/¯

    Thursday, April 17, 2014 2:06 PM