Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I plan on retiring an old file server. I noticed some of my users have mapped about 10-15 "Mapped Network Drive" to this server. Is there a script I can use to change the server name in the mappings?...in order to avoid them deleting and re-creating the mapped drives?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

this is the basic layout i use in all my domains for login scripts. i would note the

WshShell.Run "net use z: /delete", 0, False

lines... possibly make logon script that simply goes h-z deleting mapped drives and then have it map the proper ones(if any).

this is much simpler in batch script at logon by just using

net use x: /delete net use x: \server\share

i know this script is big, but it comes in handy when setting printers/drives/etc for security groups in ad.

Option Explicit
Const ADS_PROPERTY_APPEND = 3        'sets the variable to Append
Const ADS_UF_NORMAL_ACCOUNT = 512  
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
CONST HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Dim WshShell : Set WshShell = CreateObject("wscript.shell")
Dim strContainer, strUser, i, objRootDSE, strDisplayName, ObjFSO, objInFile, objContainer, strLine, strName, objOU, objGroup, objUser, objFile, objFile2, varDomainNC, objRoot, strText, FirstLine, arrMemberOf, Group, strFirstName, strLastName, strLine2, objOU2, objNetwork, strGroup, objConnection, objCommand, objRecordSet, objErrorLog, strComputer, colItems, objWMIService, colInstalledPrinters, strComputer2
Set objOU2 = GetObject("LDAP://CN=users,DC=arra,DC=local")
Set objOU = GetObject("LDAP://OU=arra-users,DC=arra,DC=local")
ObjOU.Filter= Array("user")
Set objGroup = objOU2.Getobject("group", "cn=CSRs")
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objNetwork  = WScript.CreateObject("Wscript.Network")
Set objRootDSE = GetObject("LDAP://rootDSE")
strComputer2 = "."
Dim CRLF
CRLF = Chr(13) & Chr(10)

'*************(Global Scripting) this section applies to all computers no matter what group users are in.

''default lockheed banner script
Function Ask(strAction)

    Dim intButton
    intButton = MsgBox(strAction,                   _
                       vbQuestion + vbYesNo,        _
                       L_Welcome_MsgBox_Title_Text )
    Ask = intButton = vbYes

End Function

MsgBox "This system is the property of this Corporation, and is intended for" & CRLF &   _
       "the use of authorized users only. All activities of individuals using this computer" & CRLF &   _
       "with or without authority, or in excess of their authority, may be monitored and recorded" & CRLF &   _
       "by system personnel. If any such monitoring reveals evidence of criminal activity or is in" & CRLF &   _
       "violation of foreign or U.S. state or federal law, such evidence may be provided to law" & CRLF &   _
       "enforcement officials and/or used for further legal action by this Corporation and/or the" & CRLF &   _
       "organization's Information Protection group. Unauthorized use of this system is prohibited" & CRLF &   _
       "and may result in revocation of access, disciplinary action and/or legal action. The" & CRLF &   _
       "company reserves the right to monitor and review user activity, files and electronic messages." & CRLF &   _
       "REMINDER: Information transmitted to a foreign person on this network may be subject " & CRLF &   _
       "to applicable Export Control laws. Contact your Export Coordinator for assistance." & CRLF &   _
       "(This machine is not authorized for classified processing)",   _
       vbOKOnly,   _
       "SYSTEM USE MONITORING NOTICE - IPM-003 Banner Statement"

'*************End of global scripting

''pull local computer name for loggin info.
strComputer = objNetwork.ComputerName 

''pull logon id
strUser = objNetwork.UserName

''turn logon id into container name for LDAP queries

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://" & objRootDSE.get("defaultNamingContext") & _
        ">;(&(objectCategory=User)(samAccountName=" & strUser & "));name;subtree"
Set objRecordSet = objCommand.Execute
On Error Resume Next
strUser = objRecordSet.Fields("name")
On Error GoTo 0
objConnection.Close
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

''set user to have LDAP queries run
Set objUser = GetObject("LDAP://cn=" & strUser & ",ou=arra-users,dc=arra,dc=local")

''\/\/\/\/\/\/Determine Group memberships.  PLEASE NOTE:  group names must be in UPPER case and the "Left(strGroup, X)" 
'    X must be the number of characters in the group name.
'\/\/\/\/\/\/\/

arrMemberOf = objUser.GetEx("memberOf")

If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
 For Each Group in arrMemberOf
  strGroup = UCase(Group)
  strGroup = Right(strGroup, Len(strGroup) - 3)
  If Left(strGroup, 2) = "IT" Then
  '*****IT group scripting

  ''set Z:IT drive
  WshShell.Run "net use z: /delete", 0, False
  WshShell.Run "Net use z: \\indarradc04\it", 0, False

  ''Prepare to set printers
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

  ''This prevents script from stopping when mapping network printers on the server where they
  ''are shared from
  ON ERROR RESUME NEXT

  ''Add Printers
  objNetwork.AddWindowsPrinterConnection("\\indarradc03\Xerox WorkCentre 5675 PS")

  '*****End of IT
  Else
   If Left(strGroup, 4) = "CSRS" Then
   '*****CSR group scripting

   '*****End of CSR
   Else
    If Left(strGroup, 10) = "MANAGEMENT" Then
    '*****Management group scripting - NOTE: all managers are members of "Team Leads" group

    '*****End of Management
    Else
     If Left(strGroup, 10) = "TEAM LEADS" Then
     '*****Team Lead scripting

      ''Prepare to set printers
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

      ''This prevents script from stopping when mapping network printers on the server
      ''where they are shared from
      ON ERROR RESUME NEXT

      ''Add Printers
      objNetwork.AddWindowsPrinterConnection("\\indarradc03\Xerox WorkCentre 5675 PS")

     '*****End of Team Lead
     End If
    End If
   End If
  End If
 Next
Else
 '*****Create Error Log if groups could not be determined

 Set objErrorLog = objFSO.OpenTextFile("\\indarradc04\errors\signonerrors.txt", ForAppending, True)
 objErrorLog.WriteLine strUser & " on " & strComputer & " could not be found in Active Directory on " & Date
 Err.Clear
End If
share|improve this answer
add comment

Do you run Active Directory? If so, you could just set up a logon script. Otherwise I think you're going to be doing it by hand.

share|improve this answer
1  
For the needs, I think this is the best way to map all drives. GPOs could also be a really good alternative but the login script can be easier to make... Not that much but that's my #1 choice. –  r0ca Nov 21 '09 at 23:35
add comment

Use the opportunity to 'Retire' mapped network drives. Think of other ways of acheiving the same results e.g. Group Policies.

share|improve this answer
1  
I'm in agreement with this one. If you (IT) didn't map the drives originally, they I'd say you aren't responsible for the users self-made drive mappings. Just give them fair warning, and tell them how to fix it themselves later. –  Michael Kohne Nov 21 '09 at 22:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.