使用些脚本可以禁用Exchange的帐户和邮箱。
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' bajas.vbs
' VBScript para dar de baja usuarios en el Active Directory desde un TXT
' Original Author Gustavo Riveros
' Version 1.0 - 3:35 PM Wednesday, February 08, 2006
' NOTE: EL SCRIPT Y EL "TXT CON LAS CUENTAS" DEBEN ESTAR EN EL MISMO DIRECTORIO PARA EL FUNCIONAMIENTO
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'On Error Resume Next
Option Explicit
'declaring variables...
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const ADS_UF_ACCOUNTDISABLE = 2
Dim strTxtFile, strOpenTextFile
Dim objRootDSE, strDomain
Dim WshShell, strCurrentDir
Dim objOpenFILE, objOpenTXTfile, strLine
Dim ObjConnection, ObjCommand, strConsultaLDAP
Dim objRecordSet, strADsPath, ObjUser, strEchoAttribute
Dim intUAC, strDescription
Dim ADS_SCOPE_SUBTREE
strTxtFile = "bajas.txt" 'please type your TXT file
WScript.Echo "================= START SCRIPT ================="
'obtain defaultNamingContext from W2K doamain
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set objRootDSE = nothing
'obtain current directory a txt file...
Set WshShell = WScript.CreateObject("WScript.Shell")
strCurrentDir = WshShell.CurrentDirectory
strOpenTextFile = strCurrentDir & "\" & strTxtFile
Set WshShell = nothing
'Open txt file
Set objOpenFILE = CreateObject("Scripting.FileSystemObject")
Set objOpenTXTfile = objOpenFILE.OpenTextFile(strOpenTextFile, 1)
Wscript.Echo "LDAP DOMAIN : " & strDomain
WScript.Echo "OPEN FILE : " & strOpenTextFile
wscript.echo
subReadFile
destruction
Sub subReadFile() ' in this subroutine read line4line
Do Until objOpenTXTfile.AtEndOfStream
strLine = objOpenTXTfile.ReadLine
fSearch(strLine)
'WScript.Echo strLine
Loop
objOpenTXTfile.Close
End Sub
Sub destruction() 'sub for destroy variables...
strTxtFile = 0
strOpenTextFile = 0
Set objRootDSE = Nothing
strDomain = 0
Set WshShell = Nothing
strCurrentDir = 0
Set objOpenFILE = Nothing
Set objOpenTXTfile = Nothing
strLine = 0
WScript.Echo "================= END SCRIPT ================="
End Sub
Function fSearch(strBusqueda) 'function for search, retrieve and setting object in active directory
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False ' do not cache the result, it results in less memory requirements
objCommand.Properties("Size Limit") = 1 ' Limit to 1 Result
strConsultaLDAP = "<" & strDomain & ">;(&(ObjectClass=*)(displayName=" & strBusqueda & "));AdsPath,displayName;subTree"
objCommand.CommandText = strConsultaLDAP
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
strADsPath = objRecordSet.Fields("AdsPath")
Set ObjUser = GetObject(strADsPath)
strEchoAttribute = ObjUser.get ("sAMAccountName")
WScript.Echo "setting user: " & strEchoAttribute
strDescription = "BAJA 17202544 "& Now & " [x riverog]"
intUAC = objUser.Get("userAccountControl")
objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE
ObjUser.Put "delivContLength", 1
ObjUser.Put "submissionContLength", 1
ObjUser.Put "mDBUseDefaults", false
ObjUser.Put "mDBOverHardQuotaLimit", 1
ObjUser.Put "mDBOverQuotaLimit", 1
ObjUser.Put "mDBStorageQuota", 1
ObjUser.Put "msExchHideFromAddressLists", true
ObjUser.Put "description", strDescription
ObjUser.SetInfo
WScript.Echo "Account " & objUser.sAMAccountName & " disabled!"
wscript.echo
objRecordSet.MoveNext
Wend
Set ObjUser = nothing
objConnection.Close
End Function