Solved

map network drives based on group membership powershell

Posted on 2011-09-06
2
1,830 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
[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
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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 antispam), the admini…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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