更改驱动器映射的脚本

更改驱动器映射的脚本

我计划淘汰一台旧文件服务器。我注意到我的一些用户已将大约 10-15 个“映射网络驱动器”映射到此服务器。是否有脚本可用于更改映射中的服务器名称?...以避免他们删除并重新创建映射驱动器?

答案1

这是我在所有域中用于登录脚本的基本布局。我要指出的是

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

行...可能制作登录脚本,只需以 hz 删除映射驱动器,然后让它映射正确的驱动器(如果有)。

在登录时使用批处理脚本就简单多了

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

我知道这个脚本很大,但是在为广告中的安全组设置打印机/驱动器/等时它很有用。

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

答案2

您是否运行 Active Directory?如果是,您可以设置登录脚本。否则,我认为您将手动执行此操作。

答案3

利用这个机会“退出”映射的网络驱动器。考虑其他实现相同结果的方法,例如组策略。

相关内容