切换到宽版
  • 10707阅读
  • 4回复

[求助]使用脚本查看哪些用户访问了Exchange邮箱 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-09
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:Visual Basic
  • 适合版本:Exchange 2003
  • 适用平台:
  • 脚本作用:使用些脚本文件可以对访问了Exchange邮箱的Exchange用户进行查看。
‘Who Has Access - By Alan Mosley, ThatsIT Solutions Australia

'Writes report to text file, showing who has access to Exchange users mailboxes
'Must be run on email Server

Const DOMAIN = "IT"
Const EMAIL_SERVER = "HANK"
Const LDAP_DOMAIN = "LDAP://dc=ThatsIT,dc=local"

Dim objUser
Dim oSecurityDescriptor
Dim dacl
Dim ace

Dim fso:Set fso = CreateObject("Scripting.FileSystemObject")
set tf = fso.CreateTextFile("WhoHasAccess.txt",true)
getUsers(DOMAIN)
tf.WriteLine "Who Has Access - By Alan Mosley, ThatsIT Solutions Australia"
tf.close

Sub getUsers( strDomain )
            Set objComputer = GetObject("WinNT://" & strDomain )
            objComputer.Filter = Array( "User" )
            For Each objUser In objComputer
                        writeACEs         objUser.Name
            Next
End Sub

sub writeACEs(userName)
            On Error Resume Next
            Const ADS_SCOPE_SUBTREE = 10
            Set objConnection = CreateObject("ADODB.Connection")
            Set objCommand = CreateObject("ADODB.Command")
            objConnection.Provider = "ADsDSOObject"
            objConnection.Open "Active Directory Provider"
            Set objCommand.ActiveConnection = objConnection
            objCommand.Properties("Page Size") = 1000
            objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
            objCommand.CommandText = _
                "SELECT distinguishedName FROM '"& LDAP_DOMAIN &"' WHERE objectCategory='user' " & _
                    "AND sAMAccountName='"& userName &"'"
            Set objRecordSet = objCommand.Execute
            dim ans
            objRecordSet.MoveFirst
            Do Until objRecordSet.EOF
                ans = objRecordSet.Fields("distinguishedName").Value
                objRecordSet.MoveNext
            Loop
            set objUser = GetObject("LDAP://"& EMAIL_SERVER &"/"& ans)
            Dim fullName:fullName =  Trim( objUser.FullName)
            if objUser.HomeMDB <> "" then
                        Set oSecurityDescriptor = objUser.MailboxRights
                        Set dacl = oSecurityDescriptor.DiscretionaryAcl
                        tf.WriteLine objUser.FullName
                        tf.WriteLine spaceIt("Trustee",30) & spaceIt("AccessMask",11) & spaceIt("ACEType",11) & _
                            spaceIt("ACEFlags",11) & spaceIt("Flags",11)
                        For Each ace In dacl
                                    tf.WriteLine spaceIt(ace.Trustee,30) & spaceIt(ace.AccessMask,11) & _
                                    spaceIt(ace.AceType,11) & spaceIt(ace.AceFlags,11) & spaceIt(ace.Flags,11)
                        Next
                        tf.WriteLine
                        tf.WriteLine
            end if
end sub

function spaceIt(val,spaceCount)
            dim aLine , dLen
            aLine = val
            dLen = len(aLine)
            dLen = spaceCount - dLen
            for i = 1 to dLen
                        aLine = aLine & " "
            next
            spaceIt = aLine
end function
分享到
只看该作者 1楼  发表于: 2012-09-10
如何知道这些用户从哪个IP或主机登录到Exchange的呢?求解
只看该作者 2楼  发表于: 2013-06-19
只看该作者 3楼  发表于: 2013-08-29
脚本适用于哪些版本的exchange?
只看该作者 4楼  发表于: 2014-02-13
感谢分享油墨油供应
快速回复
限60 字节
 
上一个 下一个