Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Scripiting with ifmember

Posted on 2007-11-21
5
Medium Priority
?
232 Views
Last Modified: 2010-04-16
I am writing a logon script using ifmember for my Windows 2003 domain users, but I am getting the incorrect output. I want the users to only receive the mappings they are member of, but right now they are receiving all of them.
The following is the script i wrote.
@ECHO OFF


::Group Network Drive Mappings

:HIT GLOBAL

NET USE F: /D
NET USE G: /D
NET USE I: /D
NET USE K: /D
NET USE L: /D
NET USE M: /D
NET USE N: /D
NET USE Q: /D
NET USE R: /D
NET USE V: /D
:NET USE H: /D
:NET USE H: \\Hit-ProdFile-01\%USERNAME%
NET USE J: /D
NET USE J: \\Hit-ProdFile-01\COMMON
NET USE P: /D
NET USE P: \\Hit-ProdFile-01\PUBLIC
NET USE U: /D
NET USE U: \\Hit-PST-01\%USERNAME%
NET USE Y: /D
NET USE Y: \\Hit-ProdFile-01\Projects
NeT USE Z: /D
NET USE Z: \\HIT-ArchFile-01\Archived_Data

:HIT SECURITY GROUPS

ifmember FINANCE_ACCOUNTING
if errorlevel 1 goto Management_Finance

ifmember GRAPHICS
if errorlevel 1 goto GRAPHICS

ifmember IT_GROUP
if errorlevel 1 goto IT_GROUP

ifmember PORTFOLIO MANAGEMENT
if errorlevel 1 goto PORTFOLIO_MANAGEMENT

ifmember LEGAL
if errorlevel 1 goto LEGAL

ifmember MARKETING
if errorlevel 1 goto MARKETING

ifmember SINGLE_FAMILY
if errorlevel 1 goto SINGLE_FAMILY

ifmember PUBLIC AFFAIRS
if errorlevel 1 goto PUBLIC_AFFAIRS

ifmember HUMAN_RESOURCES
if errorlevel 1 goto HUMAN_RESOURCES

ifmember MULTI_FAMILy
if errorlevel 1 goto MULTI_FAMILy

goto end

:Management_Finance
NET USE F: \\Hit-ProdFile-01\Management_Finance
:goto end

:GRAPHICS
NET USE G: \\Hit-ProdFile-01\GRAPHICS
:goto end

:IT_Group
NET USE I: \\Hit-ProdFile-01\IT
:goto end

:PORTFOLIO MANAGEMENT
NET USE K: "\\Hit-ProdFile-01\PORTFOLIO_MANAGEMENT"
:goto end

:LEGAL
NET USE L: \\Hit-ProdFile-01\Legal
:goto end

:MARKETING
NET USE M: \\Hit-ProdFile-01\Marketing
:goto end

:SINGLE_FAMILY
NET USE N: "\\Hit-ProdFile-01\SINGLE_FAMILY"
:goto end

:PUBLIC AFFAIRS
NET USE Q: "\\Hit-ProdFile-01\PUBLIC_AFFAIRS"
:goto end

:HUMAN_RESOURCES
NET USE R: "\\Hit-ProdFile-01\HUMAN_RESOURCES"
:goto end

:MULTI_FAMILY
NET USE V: "\\Hit-ProdFile-01\MULTI_FAMILY"
:goto end


:END
Exit
Any help will greatly appreciate.
Thanks and have a nice Thanks Given.
0
Comment
Question by:aflcio-hit
  • 3
  • 2
5 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 20329619
They're currently receiving most of the mappings because you started the "goto" statements with a colon, turning them into labels instead of commands.
Remove the colon at the beginning and try again:
goto end
instead of
:goto end
0
 

Author Comment

by:aflcio-hit
ID: 20329693
When I remove the colon and run the scrpit I  only receive the global mappings (4) and only one of the groupmemership mappings ( I should receive all of them).
0
 
LVL 85

Expert Comment

by:oBdA
ID: 20329762
Meaning your account is in all of the necessary groups?
Then simply replace the "goto" statements in the "if errorlevel" command with the net use commands directly, and remove everything after (and including) the "goto end" command (you don't need the "exit", the logon script will close automatically when it's done):

ifmember FINANCE_ACCOUNTING
if errorlevel 1 NET USE F: \\Hit-ProdFile-01\Management_Finance
...
0
 

Author Comment

by:aflcio-hit
ID: 20350860
   The change you recommended made a huge difference in the output, but for some unknown reason I am still not getting one mapping.
    When I copy the mapping I am mission and paste it in the run windows the shares open without any problem.
    What could be causing this?
    Thanks.
0
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 20361959
Looking closer, it should actually be two drives you don't get, K: and Q:.
As with anything that contains spaces in a command line, you need to put quotes around group names with spaces:

ifmember "PORTFOLIO MANAGEMENT"
ifmember "PUBLIC AFFAIRS"
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

926 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