我打算退休旧的文件服务器。 我注意到我的一些用户已经映射了10-15“Mapped Network Drive”到这个服务器。 有一个脚本,我可以用它来改变映射中的服务器名称?…为了避免它们删除和重新创build映射的驱动器?
这是我在我的所有域中使用login脚本的基本布局。 我会注意到的
WshShell.Run "net use z: /delete", 0, False
行…可能使login脚本,只是去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 US 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
你运行Active Directory吗? 如果是这样,你可以设置一个login脚本。 否则我想你会亲自去做。
利用这个机会'退休'映射的networking驱动器。 考虑其他方式达到相同的结果,例如组策略。