Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

map network drives based on group membership powershell

Posted on 2011-09-06
2
Medium Priority
?
1,959 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 2000 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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
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 anti-spam), the admin…
Loops Section Overview

810 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