Solved

map network drives based on group membership powershell

Posted on 2011-09-06
2
1,709 Views
Last Modified: 2012-05-12
Currently our uses get their network drives mapped depending on what active directory OU they are in ( people in the sales OU get mapped to the sales drive etc... ) . Because  a lot of our users need to access drives from other departments we end up going and mapping the drive manually for them. I was wondering if its possible to write a loggon script in powershell that will map the drives according to what group membership they have. Please consider that we have about 19 different 'drives' and as many group memberships. Would this approach make sense and is it something too complicated that isnt probably worth my time looking in too?
0
Comment
Question by:MOSADMIN
2 Comments
 
LVL 4

Accepted Solution

by:
Daelt earned 500 total points
ID: 36487758
Make a unique script for everyone and include this code in it, repeat it for each group & drive you want to setup.
Users will only connect the drives affected to the group(s) they belong to.

ON ERROR RESUME NEXT
set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")


DomainName=WshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
LogonServer=WshShell.ExpandEnvironmentStrings("%LogonServer%")
Set UserObj = GetObject("WinNT://" & DomainName & "/" & WshNetwork.username)

'wscript.echo "Hello "&WshNetwork.username&" is connecting on "&WshNetwork.computername


'Init Groups
Dim UserGroups
Dim GroupObj
UserGroups=""

For Each GroupObj In UserObj.Groups
UserGroups=UserGroups & "[" & GroupObj.Name & "]"

Next

'wscript.echo "Member of "&UserGroups


'Modify below group and network drive ......................................................................

if InGroup("Security_Group_Name") then
WshNetwork.MapNetworkDrive "X:","\\path\Folder"
end if


' Fonction Ingroup

Function InGroup(strGroup)
InGroup=False
If InStr(UserGroups,"[" & strGroup & "]") Then
InGroup=True

End If

End Function

Open in new window

0
 

Author Closing Comment

by:MOSADMIN
ID: 36487883
Excellnt, thanks a lot !
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

20 Experts available now in Live!

Get 1:1 Help Now