概要 | |||||
更多信息 | |||||
扩展 MAPI 方法 | |||||
CDO 1.21 方法 | |||||
ActiveX 数据对象 (ADO) 方法 | |||||
WebDAV 方法 | |||||
这篇文章中的信息适用于: |
'This script logs on to a server that is running Exchange Server and'displays the current number of bytes that are used in the user's'mailbox and the number of messages.' USAGE: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME' This requires that CDO 1.21 is installed on the computer.' This script is provided AS IS. It is intended as a SAMPLE only.' Microsoft offers no warranty or support for this script.' Use at your own risk.' Get command line arguments.Dim obArgsDim cArgsSet obArgs = WScript.ArgumentscArgs = obArgs.CountMainSub Main() Dim oSession Dim oInfoStores Dim oInfoStore Dim StorageUsed Dim NumMessages Dim strProfileInfo Dim sMsg On Error Resume Next If cArgs <> 2 Then WScript.Echo "Usage: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME" Exit Sub End If 'Create Session object. Set oSession = CreateObject("MAPI.Session") if Err.Number <> 0 Then sMsg = "Error creating MAPI.Session." sMsg = sMsg & "Make sure CDO 1.21 is installed. " sMsg = sMsg & Err.Number & " " & Err.Description WScript.Echo sMsg Exit Sub End If strProfileInfo = obArgs.Item(0) & vbLf & obArgs.Item(1) 'Log on. oSession.Logon , , False, True, , True, strProfileInfo if Err.Number <> 0 Then sMsg = "Error logging on: " sMsg = sMsg & Err.Number & " " & Err.Description WScript.Echo sMsg WScript.Echo "Server: " & obArgs.Item(0) WScript.Echo "Mailbox: " & obArgs.Item(1) Set oSession = Nothing Exit Sub End If 'Grab the information stores. Set oInfoStores = oSession.InfoStores if Err.Number <> 0 Then sMsg = "Error retrieving InfoStores Collection: " sMsg = sMsg & Err.Number & " " & Err.Description WScript.Echo sMsg WScript.Echo "Server: " & obArgs.Item(0) WScript.Echo "Mailbox: " & obArgs.Item(1) Set oInfoStores = Nothing Set oSession = Nothing Exit Sub End If 'Loop through information stores to find the user's mailbox. For Each oInfoStore In oInfoStores If InStr(1, oInfoStore.Name, "Mailbox - ", 1) <> 0 Then '&HE080003 = PR_MESSAGE_SIZE StorageUsed = oInfoStore.Fields(&HE080003) if Err.Number <> 0 Then sMsg = "Error retrieving PR_MESSAGE_SIZE: " sMsg = sMsg & Err.Number & " " & Err.Description WScript.Echo sMsg WScript.Echo "Server: " & obArgs.Item(0) WScript.Echo "Mailbox: " & obArgs.Item(1) Set oInfoStore = Nothing Set oInfoStores = Nothing Set oSession = Nothing Exit Sub End If '&H33020003 = PR_CONTENT_COUNT NumMessages = oInfoStore.Fields(&H36020003) if Err.Number <> 0 Then sMsg = "Error Retrieving PR_CONTENT_COUNT: " sMsg = sMsg & Err.Number & " " & Err.Description WScript.Echo sMsg WScript.Echo "Server: " & obArgs.Item(0) WScript.Echo "Mailbox: " & obArgs.Item(1) Set oInfoStore = Nothing Set oInfoStores = Nothing Set oSession = Nothing Exit Sub End If sMsg = "Storage Used in " & oInfoStore.Name sMsg = sMsg & " (bytes): " & StorageUsed WScript.Echo sMsg WScript.Echo "Number of Messages: " & NumMessages End If Next ' Log off. oSession.Logoff ' Clean up memory. Set oInfoStore = Nothing Set oInfoStores = Nothing Set oSession = NothingEnd Sub
'This script logs on to a server that is running Exchange 2000 or 2003 and'displays the current number of bytes that are used in the user's'mailbox.' USAGE: cscript MailboxSize.vbs DOMAINNAME MAILBOXNAME' You must run this code on the computer that is running Exchange 2000 or 2003.' This script is provided AS IS. It is intended as a SAMPLE only.' Microsoft offers no warranty or support for this script.' Use at your own risk.' Get command line argumentsDim obArgsDim cArgsDim iSizeSet obArgs = WScript.ArgumentscArgs = obArgs.CountMainSub Main() Dim sConnString On Error Resume Next If cArgs <> 2 Then WScript.Echo "Usage: cscript MailboxSize.vbs DOMAINNAME MAILBOXNAME" Exit Sub End If ' Set up connection string to mailbox. sConnString = "file://./backofficestorage/" & obArgs.Item(0) sConnString = sConnString & "/mbx/" & obArgs.Item(1) & "/NON_IPM_SUBTREE" WScript.Echo sConnString iSize = 0 RecurseFolder(sConnString) WScript.Echo "Mailbox Size: " & iSizeEnd SubPublic Sub RecurseFolder(sConnString) Dim oConn Dim oRecSet Dim sSQL ' Set up SQL SELECT statement. sSQL = "SELECT ""http://schemas.microsoft.com/mapi/proptag/x0e080003"", " sSQL = sSQL & """DAV:href"", " sSQL = sSQL & """DAV:hassubs"" " sSQL = sSQL & "FROM SCOPE ('SHALLOW TRAVERSAL OF """ & sConnString sSQL = sSQL & """') WHERE ""DAV:isfolder"" = true" WScript.Echo sSQL ' Create Connection object. Set oConn = CreateObject("ADODB.Connection") if Err.Number <> 0 then WScript.Echo "Error creating ADO Connection object: " & Err.Number & " " & Err.Description end if ' Create RecordSet object. Set oRecSet = CreateObject("ADODB.Recordset") if Err.Number <> 0 then WScript.Echo "Error creating ADO RecordSet object: " & Err.Number & " " & Err.Description Set oConn = Nothing Exit Sub end if ' Set provider to EXOLEDB. oConn.Provider = "Exoledb.DataSource" ' Open connection to folder. oConn.Open sConnString if Err.Number <> 0 then WScript.Echo "Error opening connection: " & Err.Number & " " & Err.Description Set oRecSet = Nothing Set oConn = Nothing Exit Sub end if ' Open Recordset of all subfolders in folder. oRecSet.CursorLocation = 3 oRecSet.Open sSQL, oConn.ConnectionString if Err.Number <> 0 then WScript.Echo "Error opening recordset: " & Err.Number & " " & Err.Description oRecSet.Close oConn.Close Set oRecSet = Nothing Set oConn = Nothing Exit Sub end if if oRecSet.RecordCount = 0 then oRecSet.Close oConn.Close Set oRecSet = Nothing Set oConn = Nothing Exit Sub end if ' Move to first record. oRecSet.MoveFirst if Err.Number <> 0 then WScript.Echo "Error moving to first record: " & Err.Number & " " & Err.Description oRecSet.Close oConn.Close Set oRecSet = Nothing Set oConn = Nothing Exit Sub end if ' Loop through all of the records, and then add the size of the ' subfolders to obtain the total size. While oRecSet.EOF <> True ' Increment size. iSize = iSize + oRecSet.Fields.Item("http://schemas.microsoft.com/mapi/proptag/x0e080003") ' If the folder has subfolders, recursively call RecurseFolder to process them. If oRecSet.Fields.Item("DAV:hassubs") = True then RecurseFolder oRecSet.Fields.Item("DAV:href") End If ' Move to next record. oRecSet.MoveNext if Err.Number <> 0 then WScript.Echo "Error moving to next record: " & Err.Number & " " & Err.Description Set oRecSet = Nothing Set oConn = Nothing Exit Sub end if wend ' Close Recordset and Connection. oRecSet.Close if Err.Number <> 0 then WScript.Echo "Error closing recordset: " & Err.Number & " " & Err.Description Set oRecSet = Nothing Set oConn = Nothing Exit Sub end if oConn.Close if Err.Number <> 0 then WScript.Echo "Error closing connection: " & Err.Number & " " & Err.Description Set oRecSet = Nothing Set oConn = Nothing Exit Sub end if ' Clean up memory. Set oRecSet = Nothing Set oConn = NothingEnd Sub
有关此主题和检索邮箱大小的 Visual C++ 示例的其他信息,请单击下面的文章编号,以查看 Microsoft 知识库中相应的文章: 'This script logs on to a server that is running Exchange Server and'displays the current number of bytes that are used in the user's'mailbox.' USAGE: cscript MailboxSize.vbs SERVERNAME MAILBOXNAME USERNAME PASSWORD' SERVERNAME: Name of your Exchange Server' MAILBOXNAME: Your alias (Note: depending on your environment, you may need to use the portion of your' SMTP address left of the '@' symbol instead of your alias.' USERNAME: Your domainname\username '' PASSWORD: Your domain password' This script is provided AS IS. It is intended as a SAMPLE only.' Microsoft offers no warranty or support for this script.' Use at your own risk.' Get command line arguments.Dim obArgsDim cArgsDim iSumSet obArgs = WScript.ArgumentscArgs = obArgs.CountMainSub Main() Dim sUrl Dim sMsg On Error Resume Next iSum = 0 ' Check argument count. If cArgs <> 4 Then sMsg = "Usage: cscript MailboxSize.vbs " sMsg = sMsg & "SERVERNAME MAILBOXNAME USERNAME PASSWORD" WScript.Echo sMsg Exit Sub End If sUrl = "http://" & obArgs.Item(0) & "/exchange/" & obArgs.Item(1) & "/NON_IPM_SUBTREE" wscript.echo sUrl RecurseFolder(sUrl) WScript.Echo "Mailbox Size: " & iSumEnd SubPublic Sub RecurseFolder(sUrl) Dim oXMLHttp Dim oXMLDoc Dim oXMLSizeNodes Dim oXMLHREFNodes Dim oXMLHasSubsNodes Dim sQuery Set oXMLHttp = CreateObject("Microsoft.xmlhttp") If Err.Number <> 0 Then WScript.Echo "Error Creating XML object" WScript.Echo Err.Number & ": " & Err.Description Set oXMLHttp = Nothing End If ' Open DAV connection. oXMLHttp.open "SEARCH", sUrl, False, obArgs.Item(2), obArgs.Item(3) If Err.Number <> 0 Then WScript.Echo "Error opening DAV connection" WScript.Echo Err.Number & ": " & Err.Description Set oXMLHttp = Nothing End If ' Set up query. sQuery = "<?xml version=""1.0""?>" sQuery = sQuery & "<g:searchrequest xmlns:g=""DAV:"">" sQuery = sQuery & "<g:sql>SELECT ""http://schemas.microsoft.com/" sQuery = sQuery & "mapi/proptag/x0e080003"", ""DAV:hassubs"" FROM SCOPE " sQuery = sQuery & "('SHALLOW TRAVERSAL OF """ & sUrl & """') " sQuery = sQuery & "WHERE ""DAV:isfolder"" = true" sQuery = sQuery & "</g:sql>" sQuery = sQuery & "</g:searchrequest>" ' Set request headers. oXMLHttp.setRequestHeader "Content-Type", "text/xml" oXMLHttp.setRequestHeader "Translate", "f" oXMLHttp.setRequestHeader "Depth", "0" oXMLHttp.setRequestHeader "Content-Length", "" & Len(sQuery) ' Send request. oXMLHttp.send sQuery If Err.Number <> 0 Then WScript.Echo "Error Sending Query" WScript.Echo Err.Number & ": " & Err.Description Set oXMLHttp = Nothing End If ' Load XML. Set oXMLDoc = oXMLHttp.responseXML ' Get the XML nodes that contain the individual sizes. Set oXMLSizeNodes = oXMLDoc.getElementsByTagName("d:x0e080003") ' Get the XML nodes that contain the individual HREFs. Set oXMLHREFNodes = oXMLDoc.getElementsByTagName("a:href") ' Get the XML nodes that contain the individual HasSubs. Set oXMLHasSubsNodes = oXMLDoc.getElementsByTagName("a:hassubs") ' Loop through the nodes, and then add all of the sizes. For i = 0 to oXMLSizeNodes.length - 1 WScript.Echo oXMLHREFNodes.Item(i).nodeTypedValue WScript.Echo "Size: " & oXMLSizeNodes.Item(i).nodeTypedValue iSum = iSum + oXMLSizeNodes.Item(i).nodeTypedValue ' If the folder has subfolders, call your recursive function to ' process subfolders. If oXMLHasSubsNodes.Item(i).nodeTypedValue = True Then RecurseFolder oXMLHREFNodes.Item(i).nodeTypedValue End If Next ' Clean up. Set oXMLSizeNodes = Nothing Set oXMLDoc = Nothing Set oXMLHttp = NothingEnd Sub
• | Microsoft Exchange Server 2003 Enterprise Edition |
• | Microsoft Exchange Server 2003 Standard Edition |
• | Microsoft Exchange 2000 Server 标准版 |
• | Microsoft Exchange Server 5.5 标准版 |
关键字: | kbhowto KB320071 |
自由广告区 |
分类导航 |
邮件新闻资讯: IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮 电子邮箱 | 反垃圾邮件|邮件客户端|网络安全 行业数据 | 邮件人物 | 网站公告 | 行业法规 网络技术: 邮件原理 | 网络协议 | 网络管理 | 传输介质 线路接入 | 路由接口 | 邮件存储 | 华为3Com CISCO技术 | 网络与服务器硬件 操作系统: Windows 9X | Linux&Uinx | Windows NT Windows Vista | FreeBSD | 其它操作系统 邮件服务器: 程序与开发 | Exchange | Qmail | Postfix Sendmail | MDaemon | Domino | Foxmail KerioMail | JavaMail | Winwebmail |James Merak&VisNetic | CMailServer | WinMail 金笛邮件系统 | 其它 | 反垃圾邮件: 综述| 客户端反垃圾邮件|服务器端反垃圾邮件 邮件客户端软件: Outlook | Foxmail | DreamMail| KooMail The bat | 雷鸟 | Eudora |Becky! |Pegasus IncrediMail |其它 电子邮箱: 个人邮箱 | 企业邮箱 |Gmail 移动电子邮件:服务器 | 客户端 | 技术前沿 邮件网络安全: 软件漏洞 | 安全知识 | 病毒公告 |防火墙 攻防技术 | 病毒查杀| ISA | 数字签名 邮件营销: Email营销 | 网络营销 | 营销技巧 |营销案例 邮件人才:招聘 | 职场 | 培训 | 指南 | 职场 解决方案: 邮件系统|反垃圾邮件 |安全 |移动电邮 |招标 产品评测: 邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端 |