Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scripiting with ifmember

Posted on 2007-11-21
5
Medium Priority
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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