切换到宽版
  • 13194阅读
  • 3回复

[求助]使用脚本禁用Exchange帐户和邮箱 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-11
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:Visual Basic
  • 适合版本:Exchange 2003
  • 适用平台:
  • 脚本作用:禁用Exchange帐户和邮箱
使用些脚本可以禁用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
分享到
只看该作者 1楼  发表于: 2011-03-11
不错
只看该作者 2楼  发表于: 2012-03-05
不会修改。看不太董
只看该作者 3楼  发表于: 2012-10-21
对我等脚本小白来说,完全看不懂……
能否简单指导一下,比如哪个地方是公司域名/邮件服务器地址/IP,哪个地方读取需要处理的用户列表
快速回复
限60 字节
 
上一个 下一个