Solved

Scripiting with ifmember

Posted on 2007-11-21
5
214 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 83

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 83

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 83

Accepted Solution

by:
oBdA earned 500 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now