Solved

map network drives based on group membership powershell

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A brief introduction to what I consider to be the best editor for PowerShell.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

22 Experts available now in Live!

Get 1:1 Help Now