Solved

Scripiting with ifmember

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

17 Experts available now in Live!

Get 1:1 Help Now