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
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
' +++++++++++++++++++++++++++++++++THIS 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
'On Error Resume Next
'++++++++++++++++++++++++++++++because Symantec s***s, we must sleep++++++++++++++++++++++++
'WScript.Sleep 3000 'miliseconds
'++++++++++++++++++++++++NEXT remove existing mappings+++++++++++++++++++++++++++++++
Dim oNet, oDrives, nDrive, i
Set oNet = CreateObject("Wscript.Network")
Set oDrives = oNet.EnumNetworkDrives
For i = 0 To oDrives.Count-1 Step 2
' +++++++++++++++++++++++ "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("Wscript.Network")
Set clPrinters = WshNet.EnumPrinterConnections
On Error Resume Next
For n = 0 To clPrinters.Count - 1 Step 2
WSHNet.RemovePrinterConnection clPrinters.Item(n+1), True
'++++++++++++++++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++++++++++++++++++++++
Set objNetwork = CreateObject("WScript.Network")
WScript.echo "common drives"
objNetwork.MapNetworkDrive "S:", "\\R105002\shared"
objNetwork.MapNetworkDrive "I:", "\\R105002\intercept"
'++++++++++++Only domain admins get the N Drive****************************************
' 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.MemberOf)>0 Then
strGroup = LCase(Join(currentuser.MemberOf))
' +++++++++++++++++++BEGIN DRIVE MAPPING PER GROUP MEMBERSHIP+++++++++++++++++++
If InStr(strGroup, DomAd) Then
' WScript.Echo "You are logged into the IT Group "
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"
'+++++++++++++++++++++++++Some Drives are on site server, so they are mapped by AD site+++++++++++++++++++++++++++++++
Dim objSYSInfo, objNetW
Set objSysInfo = WScript.CreateObject("ADSystemInfo")
'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("WScript.Network")
'holds our user's name
Set objADSUser = GetObject("LDAP://" & objSYSInfo.username)
' This simply forces LDAP to perform as the dirctory lookup protocol
Set objADSOU = GetObject(objADSUser.parent)
WScript.echo "here we set the site" & objADUser.parent
' hmm so the ADSysteminfo.username.parent method returns the OU of the user?
'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
'Function IsIndirectMemberOfOU(OUName) 'the user is somewher under the OU specified
'IsIndirectMemberOfOU = False
'If InStr(UCase(objADSOU.adspath),UCase(OUName)) Then
' IsIndirectMemberOfOU = True
'Function IsMemberOfGroup(GroupName) 'the user is a member of a specified group
'IsMemberOfGroup = False
'Set objGroup = GetObject("WinNT://" & objNetW.UserDomain & "/" & GroupName & ",group")
'IsMemberOfGroup = objGroup.IsMember(objWinntUser.ADsPath)
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_Pwest") Then objNetW.MapNetworkDrive "z:", "\\R227002\home" & objADSUser