Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Script is being strange

Posted on 2016-11-04
8
Medium Priority
?
92 Views
Last Modified: 2016-11-17
I have this script:
Set objNetwork = CreateObject("WScript.Network")
 Set objUser = CreateObject("ADSystemInfo")
 Set objCurrentUser = GetObject("LDAP://" & objUser.UserName)
Set objFSO = CreateObject("Scripting.FileSystemObject")
 If IsArray(objCurrentUser.MemberOf) Then
  strGroup = LCase(Join(objCurrentUser.MemberOf))
Else
  strGroup = LCase(objCurrentUser.MemberOf)
End If

If InStr(strGroup, lcase("CN=Users")) Then
If objFSO.DriveExists("O:") = False Then objNetwork.MapNetworkDrive "O:", "\\wscalfs\Company"
End If

 If InStr(strGroup, lcase("CN=Development")) Then
 If objFSO.DriveExists("W:") = False Then objNetwork.MapNetworkDrive "W:", "\\wscalfs\Development"
End If

 If InStr(strGroup, lcase("CN=Admissions")) Then
If objFSO.DriveExists("R:") = False Then objNetwork.MapNetworkDrive "R:", "\\wscalfs\Admissions"
End If

 If InStr(strGroup, lcase("CN=Recruitment")) Then
If objFSO.DriveExists("W:") = False Then objNetwork.MapNetworkDrive "W:", "\\wscalfs\Recruitment"
End If  

 If InStr(strGroup, lcase("CN=Financial Aid")) Then
If objFSO.DriveExists("M:") = False Then objNetwork.MapNetworkDrive "M:", "\\wscalfs\FinancialAid"
End If

 If InStr(strGroup, lcase("CN=Quickbooks")) Then
If objFSO.DriveExists("Q:") = False Then objNetwork.MapNetworkDrive "Q:", "\\wscalfs\Quickbooks"
End If  

 If InStr(strGroup, lcase("CN=Business Office")) Then
If objFSO.DriveExists("R:") = False Then objNetwork.MapNetworkDrive "R:", "\\wscalfs\BusinessOffice"
End If  

 If InStr(strGroup, lcase("CN=Administration")) Then
 If objFSO.DriveExists("M:") = False Then objNetwork.MapNetworkDrive "M:", "\\wscalfs\Administration"
End If

 If InStr(strGroup, lcase("CN=Registrar")) Then
If objFSO.DriveExists("T:") = False Then objNetwork.MapNetworkDrive "T:", "\\wscalfs\Registrar"
End If  

 If InStr(strGroup, lcase("CN=Users")) Then
If objFSO.DriveExists("S:") = False Then objNetwork.MapNetworkDrive "S:", "\\wscalfs\scans"
End If

I have a user who has the correct permissions but it is throwing an error on line 28 character 42 of "The network path was not found".  I am not sure what line that is, if it deals with Business Office or Recruitment, but there is no difference in the code at that point than there is prior to that.  I ran the script on myself with the same permissions and it completes successfully.
0
Comment
Question by:aclaus225
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 13

Expert Comment

by:Jeff Darling
ID: 41874549
This kind of odd behavior is often due to not declaring variables.

Turn on OPTION EXPLICIT and declare all variables.
0
 
LVL 13

Accepted Solution

by:
Jeff Darling earned 1000 total points
ID: 41874553
Option Explicit

Dim objNetwork
Dim objUser
Dim objCurrentUser
Dim objFSO
Dim strGroup

Set objNetwork = CreateObject("WScript.Network")
 Set objUser = CreateObject("ADSystemInfo")
 Set objCurrentUser = GetObject("LDAP://" & objUser.UserName)
Set objFSO = CreateObject("Scripting.FileSystemObject")
 If IsArray(objCurrentUser.MemberOf) Then
  strGroup = LCase(Join(objCurrentUser.MemberOf))
Else
  strGroup = LCase(objCurrentUser.MemberOf)
End If

If InStr(strGroup, lcase("CN=Users")) Then
If objFSO.DriveExists("O:") = False Then objNetwork.MapNetworkDrive "O:", "\\wscalfs\Company"
End If

 If InStr(strGroup, lcase("CN=Development")) Then 
 If objFSO.DriveExists("W:") = False Then objNetwork.MapNetworkDrive "W:", "\\wscalfs\Development"
End If 

 If InStr(strGroup, lcase("CN=Admissions")) Then
If objFSO.DriveExists("R:") = False Then objNetwork.MapNetworkDrive "R:", "\\wscalfs\Admissions"
End If 

 If InStr(strGroup, lcase("CN=Recruitment")) Then 
If objFSO.DriveExists("W:") = False Then objNetwork.MapNetworkDrive "W:", "\\wscalfs\Recruitment"
End If  

 If InStr(strGroup, lcase("CN=Financial Aid")) Then
If objFSO.DriveExists("M:") = False Then objNetwork.MapNetworkDrive "M:", "\\wscalfs\FinancialAid"
End If 

 If InStr(strGroup, lcase("CN=Quickbooks")) Then
If objFSO.DriveExists("Q:") = False Then objNetwork.MapNetworkDrive "Q:", "\\wscalfs\Quickbooks"
End If  

 If InStr(strGroup, lcase("CN=Business Office")) Then 
If objFSO.DriveExists("R:") = False Then objNetwork.MapNetworkDrive "R:", "\\wscalfs\BusinessOffice"
End If  

 If InStr(strGroup, lcase("CN=Administration")) Then
 If objFSO.DriveExists("M:") = False Then objNetwork.MapNetworkDrive "M:", "\\wscalfs\Administration"
End If

 If InStr(strGroup, lcase("CN=Registrar")) Then 
If objFSO.DriveExists("T:") = False Then objNetwork.MapNetworkDrive "T:", "\\wscalfs\Registrar"
End If  

 If InStr(strGroup, lcase("CN=Users")) Then
If objFSO.DriveExists("S:") = False Then objNetwork.MapNetworkDrive "S:", "\\wscalfs\scans"
End If 

Open in new window

0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 1000 total points
ID: 41874555
Add some error handling and see what you get...
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set objCurrentUser = GetObject("LDAP://" & objUser.UserName)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set dic = createobject("scripting.dictionary")

If IsArray(objCurrentUser.MemberOf) Then
  strGroup = LCase(Join(objCurrentUser.MemberOf))
Else
  strGroup = LCase(objCurrentUser.MemberOf)
End If

If InStr(strGroup, lcase("CN=Users")) Then dic.add "O:","\\wscalfs\Company"
If InStr(strGroup, lcase("CN=Development")) Then dic.add "W:", "\\wscalfs\Development"
If InStr(strGroup, lcase("CN=Admissions")) Then dic.add "R:", "\\wscalfs\Admissions"
If InStr(strGroup, lcase("CN=Recruitment")) Then dic.add "W:", "\\wscalfs\Recruitment"
If InStr(strGroup, lcase("CN=Financial Aid")) Then dic.add "M:", "\\wscalfs\FinancialAid"
If InStr(strGroup, lcase("CN=Quickbooks")) Then dic.add "Q:", "\\wscalfs\Quickbooks"
If InStr(strGroup, lcase("CN=Business Office")) Then dic.add "R:", "\\wscalfs\BusinessOffice"
If InStr(strGroup, lcase("CN=Administration")) Then dic.add "M:", "\\wscalfs\Administration"
If InStr(strGroup, lcase("CN=Registrar")) Then dic.add "T:", "\\wscalfs\Registrar"
If InStr(strGroup, lcase("CN=Users")) Then dic.add "S:", "\\wscalfs\scans"



for each DriveLetter in dic.keys
  on error resume next
  TargetPath = dic(DriveLetter)
  wscript.echo "Mapping " & DriveLetter & " to " & TargetPath
  If objFSO.DriveExists(DriveLetter) = False Then objNetwork.MapNetworkDrive DriveLetter, TargetPath
  if err.number <> 0 then 
    wscript.echo err.description
  else 
    wscript.echo "Mapped successfully"
  end if
  err.clear
next

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:aclaus225
ID: 41877980
I tried the script recommended by Jeff and it errors at the same place again.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 41878040
And mine?
0
 
LVL 13

Expert Comment

by:Jeff Darling
ID: 41879012
try the NET USE command from a DOS box to display current mapped network drives.

Do it on a good machine and on a bad machine and compare the differences.

You may need to manually NET USE /DELETE one or more of the drives in order for the script to work, or it could be some weird Active Directory permissions inheritance that is unique to your location.
0
 

Author Comment

by:aclaus225
ID: 41879085
At logout every day there is also a script that runs:
net use G: /delete
net use H: /delete
net use I: /delete
net use J: /delete
net use K: /delete
net use L: /delete
net use M: /delete
net use N: /delete
net use O: /delete
net use P: /delete
net use Q: /delete
net use R: /delete
net use S: /delete
net use T: /delete
net use U: /delete
net use V: /delete
net use W: /delete
net use X: /delete
net use Y: /delete
net use Z: /delete

Open in new window


Therefore, the computers are starting fresh at start up every day.  

As for your script Sirbounty,
that script works on my machine just fine.  On the registrar's computer I get an error, which I have attached.
anothererror.png
0
 

Author Closing Comment

by:aclaus225
ID: 41891946
I ended up just doing custom scripts for each department using a Batch file which seems to be working for everyone.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Let's recap what we learned from yesterday's Skyport Systems webinar.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

636 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