Okay, here's the whole script. I'm trying to map drives and printers based on AD site or membership in groups and OU's. I think this suffers from bloat.
I get the printers removed just fine.
The existing network drives enter the state of being disconnected, but do not disappear. Opening one in this state immediately reconnects it.
I frequently (but not always) get an error 80070057, The parameter is incorrect on line 33
oNet.RemoveNetworkDrive oDrives.Item(i)
This is usually fixed ( for a while) by changing the 0 from the line above to a 1 or 2, saving, then changing it back.
I get the 'common drives', and EVERYONE gets the privalaged drives. but no new printer mapping based on site occurs
Thanks for your help
' the ucase command returns the input in all caps
' ++++++++++++++++++++++++++
+++++++THI
S IS THE BASE PRINTER AND DRIVE MAPPING SCRIPT ++++++++++++++++++++++++++
++++++++++
++++++++++
' +++purpose is to remove any existing drive and printer mappings, then create new/apprpirate ones based on AD group membership.+++
'start of script
Option Explicit
'On Error Resume Next
'+++++++++++++++++++++++++
+++++becau
se Symantec s***s, we must sleep+++++++++++++++++++++
+++
'WScript.Sleep 3000 'miliseconds
'++++++++++++++++++++++++N
EXT remove existing mappings++++++++++++++++++
++++++++++
+++
Dim oNet, oDrives, nDrive, i
Set oNet = CreateObject("Wscript.Netw
ork")
Set oDrives = oNet.EnumNetworkDrives
For i = 0 To oDrives.Count-1 Step 2
oNet.RemoveNetworkDrive oDrives.Item(i)
WScript.echo i
Next
' +++++++++++++++++++++++ "end drive removal"++++++++++++++++++
++++++++++
++++++++++
++
'+++++++++++++++++++++BULK
PRINTER REMOVAL BEGIN+++++++++++++++++++++
+
WScript.echo "Begin by removing all mapped printers To unconfuse users"
Dim WSHNet, wshNetwork
Dim clprinters, n
Set WSHNet= WScript.CreateObject("Wscr
ipt.Networ
k")
Set clPrinters = WshNet.EnumPrinterConnecti
ons
On Error Resume Next
For n = 0 To clPrinters.Count - 1 Step 2
WSHNet.RemovePrinterConnec
tion clPrinters.Item(n+1), True
Next
'++++++++++++++++END BULK PRINTER REMOVAL+++++++++++++++++++
+
'+++++++++++++++++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
+++++
' ++++++++++++Okay, now that we have had our dose of fiber and are all clean, let's start adding objects+++++++++++++++++
'+++++++++++++++++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
+++++
'+++++++++++++Some of my drives get mapped no matter who you are++++++++++++++++++++++
Dim objNetwork
Set objNetwork = CreateObject("WScript.Netw
ork")
WScript.echo "common drives"
objNetwork.MapNetworkDrive
"S:", "\\R105002\shared"
objNetwork.MapNetworkDrive
"I:", "\\R105002\intercept"
'++++++++++++Only domain admins get the N Drive*********************
**********
*********
Dim strGroup
' Dim currentuser
' Dim objectUser
' Dim net
' Dim objprinter
WScript.echo "privalaged drives"
' here we creat pegs for the AD groups
Const DomAd = "Domain Admins"
WScript.echo "Now we see which group the member belongs To"
Set objectUser = CreateObject("ADSystemInfo
")
WScript.echo "next line"
Set currentuser = GetObject("LDAP://" & objectUser.UserName)
WScript.echo "active directoroy group based drive mapping"
WScript.echo objuser & currentuser
If UBound(currentuser.MemberO
f)>0 Then
strGroup = LCase(Join(currentuser.Mem
berOf))
Else strGroup=currentuser.Membe
rOf(0)
WScript.echo strGroup
End If
' +++++++++++++++++++BEGIN DRIVE MAPPING PER GROUP MEMBERSHIP++++++++++++++++
+++
If InStr(strGroup, DomAd) Then
' WScript.Echo "You are logged into the IT Group "
WScript.echo strGroup
objNetwork.MapNetworkDrive
"N:", "\\R105002\install"
objNetwork.MapNetworkDrive
"H:", "\\R105002\home"
objNetwork.MapNetworkDrive
"S:", "\\R052002\home"
objNetwork.MapNetworkDrive
"P:", "\\R227002\home"
objNetwork.MapNetworkDrive
"M:", "\\R221002\home"
End If
'+++++++++++++++++++++++++
Some Drives are on site server, so they are mapped by AD site++++++++++++++++++++++
+++++++++
Dim objSYSInfo, objNetW
Set objSysInfo = WScript.CreateObject("ADSy
stemInfo")
'a good example of how ADSystemInfo works is
' Set objAD = CreateObject("ADSystemInfo
")
' Wscript.Echo "Your Computer Name is " & objAD.ComputerName
' WScript.Echo "Your Username is " & objAD.UserName
Set objNetW = WScript.CreateObject("WScr
ipt.Networ
k")
Dim objADSUser
'holds our user's name
Set objADSUser = GetObject("LDAP://" & objSYSInfo.username)
' This simply forces LDAP to perform as the dirctory lookup protocol
Dim objADSOU
Set objADSOU = GetObject(objADSUser.paren
t)
WScript.echo "here we set the site" & objADUser.parent
' hmm so the ADSysteminfo.username.pare
nt method returns the OU of the user?
'Dim objWinntUser
'Set objWinntUser = GetObject("WinNT://" & objNetW.UserDomain & "/" & objNetW.UserName & ",user")
'This forces WinNT/NeRIOS to act as the directory
'******* end of objects declarations
Dim strOU, StrGrP
'strOU = "_davidstestou"
'StrGrP = "Domain Admins"
' This is just feeding in known false data to prove the comparison below
'uncomment for testing
'MsgBox objNetW.username & " is directly inside the " & strOU & " OU = " & IsDirectMemberOfOU(strOU)
'MsgBox objNetW.username & " is directly or indirectly inside the " & strOU & " OU = " & IsIndirectMemberOfOU(strOU
)
'MsgBox objNetW.username & " is a member of the " & StrGrP & " group = " & IsMemberOfGroup(StrGrP)
'IsDirectMemberOfOU is just a bucket that hold a true or false value, see the 1st function.
MsgBox "note the difference in paths for the different protocols:" & vbCrLf & _
"User ADSPath(LDAP) = " & objADSUser.adspath
' "User ADSPath(Winnt) = " & objWinntUser.adspath & vbCrLf & _
'***** End of main script, All functions and subs below *****
'Function IsDirectMemberOfOU(OUName)
'the user is contained directly within the OU
'IsDirectMemberOfOU = False
'If UCase(objADSOU.OU) = UCase(OUName) Then
' IsDirectMemberOfOU = True
'End If
'End Function
'Function IsIndirectMemberOfOU(OUNam
e) 'the user is somewher under the OU specified
'IsIndirectMemberOfOU = False
'If InStr(UCase(objADSOU.adspa
th),UCase(
OUName)) Then
' IsIndirectMemberOfOU = True
'End If
'End Function
'Function IsMemberOfGroup(GroupName)
'the user is a member of a specified group
'IsMemberOfGroup = False
'Dim objGroup
'Set objGroup = GetObject("WinNT://" & objNetW.UserDomain & "/" & GroupName & ",group")
'IsMemberOfGroup = objGroup.IsMember(objWinnt
User.ADsPa
th)
'End Function
WScript.exho objADSOU.OU
If UCase(objADSOU.OU) = UCase("OU_MtP") Then objNetW.MapNetworkDrive "z:", "\\R105002\home\" & objADSUser
If UCase(objADSOU.OU) = UCase("OU_Operations") then objNetW.MapNetworkDrive "z:", "\\R105002\home\" & objADSUser
If UCase(objADSOU.OU) = UCase("OU_Pwest") Then objNetW.MapNetworkDrive "z:", "\\R105002\home\" & objADSUser
If UCase(objADSOU.OU) = UCase("OU_serT") Then objNetW.MapNetworkDrive "z:", "\\R052002\home\" & objADSUser
If UCase(objADSOU.OU) = UCase("OU_MBs") Then objNetW.MapNetworkDrive "z:", "\\R221002\home\" & objADSUser
'uncomment after move
'If IsIndirectMemberOfOU("OU_P
west") Then objNetW.MapNetworkDrive "z:", "\\R227002\home" & objADSUser
Start Free Trial