Re: Drive maping help




Good catch Al, I don't know how that happened. I did some copy'n'paste and must
have left something out when removing some debug echos.

This is what I should have pasted:


'===========================================
Option Explicit

Dim WSHNetwork
Set WSHNetwork = WScript.CreateObject("WScript.Network")

' Fix this next line if it wrapped, If .... Then should be on one line:
If CheckOUMembership(WSHNetwork.username,
"LDAP://OU=Accounting,OU=Departments,DC=domain,DC=com";) Then
WScript.Echo "DEBUG: Mapping drive T:"
WSHNetwork.MapNetworkDrive "T:", "\\SERVER\Share$"
End If

WScript.Quit


Function CheckOUMembership(ByVal Account, ByVal OU)
CheckOUMembership = False
Dim objAccount, objDomain
Set objAccount = Nothing
Set objDomain = GetObject(OU)

For Each objAccount in objDomain
' The object class can be User, Group, Computer or Schema.
If UCase(objAccount.Class) = "USER" Then
If UCase(objAccount.Name) = UCase("CN=" & Account) Then
CheckOUMembership = True
Exit For
End If
End If
Next
End Function
'===========================================





"Al Dunbar [MS-MVP]" <alan-no-drub-spam@xxxxxxxxxxx> wrote in message
news:OPuAxC6UGHA.5852@xxxxxxxxxxxxxxxxxxxxxxx
Thanks for doing the legwork on this one, Marty! ;-)


But wait a minute. On second reading of your script, it seems to me that
function "CheckOUMembership" will return a TRUE value if the specified OU
contains ANY objects of type "USER". Seems to me it should be doing this
only if the user found has the same name as what is stored in the "Account"
parameter.

Using the OU is probably the simplest way to ensure each user has only one
"affiliation" or "membership". Just remember that OU membership has other
uses than to organize drive mappings. If your IT department decides, for
example, to collapse OU's because they are changing their account
administration model, well, you will need to be able to deal with the
result.

To make this approach a bit scaleable, I would be tempted to avoid the
literal approach of: if in this OU do this, elseif in this other OU do this.
Specifically, I would determine the user's OU as being the parent of his
distinguished name, concatenate the OU names (i.e. "Accounting-Department"),
look for a file of that name on the domain controller, and read the name of
the drive to map from that file. This approach also avoids having to
enumerate all objects in the OU in question.


/Al

"Marty List" <usenet@xxxxxxxxxxxx> wrote in message
news:uIleRy1UGHA.5592@xxxxxxxxxxxxxxxxxxxxxxx

Jim,

Try this script, I think this is what you are asking for. There's
probably a
faster/more efficient way of doing this, and personally I would use more
variable names, but this way should be easier to understand if you're just
getting started.


'===========================================
Option Explicit

Dim WSHNetwork
Set WSHNetwork = WScript.CreateObject("WScript.Network")

' Fix this next line if it wrapped, If .... Then should be on one line:
If CheckOUMembership(WSHNetwork.username,
"LDAP://OU=Accounting,OU=Departments,DC=domain,DC=com";) Then
WScript.Echo "DEBUG: Mapping drive T:"
WSHNetwork.MapNetworkDrive "T:", "\\SERVER\Share$"
End If

WScript.Quit


Function CheckOUMembership(ByVal Account, ByVal OU)
CheckOUMembership = False
Dim objAccount, objDomain
Set objAccount = Nothing
Set objDomain = GetObject(OU)

For Each objAccount in objDomain
' The object class can be User, Group, Computer or Schema.
If UCase(objAccount.Class) = "USER" Then
'WScript.Echo "DEBUG: " & objAccount.Name & ": " &
objAccount.FullName
CheckOUMembership = True
Exit For
End If
Next
End Function
'===========================================




"Jim" <Jim@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E66E1A75-BCDB-4C57-A2D4-A37EC272B766@xxxxxxxxxxxxxxxx
Al

Thank you; you deciphered what I needed perfectly

One last question to solve the issue of the user being in multiple
groups is
it possible instead to use the Organizational Units name to setup the T:
map?

Thanks again
Jim


"Al Dunbar [MS-MVP]" wrote:


"Jim" <Jim@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0E2D6115-AF77-4B01-95C2-B05D40104404@xxxxxxxxxxxxxxxx
when a user logs in i would like this script to run as part of a
Group
policy
to automatically map drive T and V for every user. also is it
possible to
change the groupname variable

hold on, your script does not reference a groupname variable.

so that if for example the groupname = "PR_grp"
that the T: drive is mapped to \\servername\Payroll

=========
Dim WSHNetwork
Set WSHNetwork = WScript.CreateObject("WScript.Network")

WSHNetwork.MapNetworkDrive "T:", "\\Servername\Groupname"
WSHNetwork.MapNetworkDrive "V:", "\\Servername\logonname"

As written, the above code will map a share whose name is, literally
"groupname" on a server whose name is "servername" to drive T: and to
similarly map a share whose name is "logonname".

If your intention is that the actual sharenames differ from user to
user,
the simplest one to implement is V:

WSHNetwork.MapNetworkDrive "V:", "\\Servername\" &
WSHNetwork.username

If the user account is named "ElmerFudd", then V: would map to
\\Servername\ElmerFudd.

This is pretty straightforward, because the concept: "name of current
user"
is understood by all parties. What is not clear is what you refer to as
"groupname", as this has no particular meaning here.

What I suspect you want is along these lines:

if user is in the group named "PR_grp" then
map T: to \\servername\Payroll
elseif user is in the group named "FI_grp" then
map T: to \\servername\Finance
... etc ...

The trouble is that there is nothing to constrain ones group
memberships to
only one of a set number of groups. What should T: map to, for example,
when
the user is found to be a member of PR_grp and FI_grp?

/Al

==========

the servername i will fill in. what i need help with is Groupname and
Username so i dont have to create over 200 of these for all of our
users.

after thinking a little more on this the groupname should be the
OUname as
they could be a member of many groups but only one OU


jim




"Marty List" wrote:


Explain what you mean by "insert". To me that means type or paste
it
into
Notepad, but I doubt that's what you need help on :) Are you
trying to
pass
variables to the script on the command line?

When you say "a script", which scripting language are you referring
to?
Do you
already have a script or a sample you're working with?


"Jim" <Jim@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D7FE7947-06BC-4972-82C8-EE4428899FD8@xxxxxxxxxxxxxxxx

is there a way to insert the user and group name into a script to
map
network drives?


thanks
Jim













.



Relevant Pages

  • Re: Default password for Active Directory User Script
    ... but you already filtered the objDomain object to only ... EnumerateUsers should be a Sub. ... 'Command to map a drive. ...
    (microsoft.public.windows.server.scripting)
  • Newbie: Why does SAMBA authentication fail?
    ... The problem is I can't map a drive to it from my Win XP box. ... ldap delete dn = No ...
    (comp.os.linux.misc)
  • Re: troubleshoot a script
    ... I see you use the memberOf attribute. ... ' map appropriate drives. ... The part of the script that will not work for the 3 ...
    (microsoft.public.scripting.vbscript)
  • Re: Drive maping help
    ... Try this script, I think this is what you are asking for. ... Dim WSHNetwork ... it possible instead to use the Organizational Units name to setup the T: map? ... your script does not reference a groupname variable. ...
    (microsoft.public.windows.server.scripting)
  • Re: Limit desktop & start menu
    ... Create a login script that runs when users log into the TS, and map the R: ... persisitent "R" drive on the server itself and that may cure it. ...
    (microsoft.public.windows.terminal_services)