Usuário com melhor resposta
Como consultar se mailbox esta cheia via linha de comando, base de dados do Exchange 2003.

Pergunta
-
Pessoal, bom dia.
Necessito descobrir como faço para consultar a base de dados do exchange via linha de comando, e descobrir quem são os usuários que estão com a caixa postal cheia, e se possível aumentar a caixa postal em 5 Mega. Sendo meu Servidor Windows 2003 com AD, meu domínio seria infoed.local. Já pesquisei bastante mas para consultar a base do exchange ainda não consegui nada. Já consigo consultar logins usando o dsquery.
Desse modo posso oferecer uma ferramenta de consulta e alteração no AD, sem precisar acessar o Servidor ou ser Domain Admins.
Agradeço a atenção.terça-feira, 30 de setembro de 2008 13:25
Respostas
-
Encontrei o seguinte script, porém não sei exatamente oque será executado, devido a complexidade, alguém sabe me dizer se é seguro?
Fonte: http://www.flobee.net/?view=plink&id=114
Option Explicit
Dim objGC, objOU, strADPath
Dim strUserLoginName
Dim objADOCnxn, objADOCmd, strSearchFilter, strReturnAttrib, strSearchDepth, objResults, intMatchingRecords
Dim strUserDisplayName, strRawExchServer, strExchServer
Dim wmiConn, strWQL, wmiColl, wmiObj
Dim mbstore, strquota, stroverquota, strHardLimit, strmbsize, strquotasum
'
' Messages to be displayed if the scripting host is not cscript
'
Const kMessage1 = "Please run this script using CScript."
Const kMessage2 = "This can be achieved by"
Const kMessage3 = "1. Using ""CScript script.vbs arguments"" or"
Const kMessage4 = "2. Changing the default Windows Scripting Host to CScript"
Const kMessage5 = " using ""CScript //H:CScript //S"" and running the script "
Const kMessage6 = " ""script.vbs arguments""."
' Make sure running with CScript
If Not IsHostCscript() Then
Call WScript.echo(kMessage1 & vbCRLF & kMessage2 & vbCRLF & _
kMessage3 & vbCRLF & kMessage4 & vbCRLF & _
kMessage5 & vbCRLF & kMessage6 & vbCRLF)
WScript.quit
End If
' Connect to a global catalog for the forest
Set objGC = GetObject("GC:")
For Each objOU In objGC
strADPath = "<" & objOU.AdsPath & ">"
Next
Set objOU = Nothing
Set objGC = Nothing
WScript.Echo "* Searching within: " & strADPath
' Get input - strUserLoginName
strUserLoginName = InputBox("This will search for the user's mailbox and display its size." & _
vbCrLf & vbCrLf & "Enter a user's login name, or" & vbCrLf & "their primary SMTP address:" & _
vbCrLf & vbCrLf & "(LDAP wildcard characters are supported.)")
If strUserLoginName = "" Then
WScript.Echo "User Canceled"
WScript.Quit
End If
' Use ADO to query on the given user login name
Set objADOCnxn = CreateObject("ADODB.Connection")
objADOCnxn.Provider = "ADsDSOObject"
objADOCnxn.Open "Active Directory Provider"
Set objADOCmd = CreateObject("ADODB.Command")
objADOCmd.ActiveConnection = objADOCnxn
strSearchFilter ="(&(objectCategory=person)(|(mail=" & strUserLoginName & ")(samAccountName=" & strUserLoginName & ")))"
strReturnAttrib = "displayName,msExchHomeServerName,samAccountName,mdbUseDefaults,homemdb,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit"
strSearchDepth = "SubTree"
objADOCmd.CommandText = strADPath & ";" & strSearchFilter & ";" & strReturnAttrib & ";" & strSearchDepth
Set objResults = objADOCmd.Execute
intMatchingRecords = objResults.RecordCount
WScript.Echo " AD Search Returned " & intMatchingRecords & " Records" & vbCrLf
If intMatchingRecords < 1 Then
' User name was not found
MsgBox "The specified string was not found!" & vbCrLf & vbCrLf & "No matching user name or SMTP address(es)", 0, "Search Results"
Else
' We found a match, for each record in result set...
Do
strUserDisplayName = objResults.Fields("displayName").value
strRawExchServer = objResults.Fields("msExchHomeServerName").value
' only proceed if the msExchHomeServerName attribute contains an '=' character
If InStr(1, strRawExchServer, "=", vbTextCompare) Then
' Parse out the actual Exchange server name (everything to right of last '=')
strExchServer = Mid(strRawExchServer,InStrRev(strRawExchServer, "=", -1, vbTextCompare) + 1)
' Create a WMI connection to that server
Set wmiConn = GetObject("WinMgmts:{impersonationLevel=impersonate}!\\" & strExchServer & "\root\microsoftexchangev2")
' Search for the display name of the user
WScript.Echo "* Looking for '" & strUserDisplayName & "' on server " & strExchServer
strWQL = "SELECT * FROM Exchange_Mailbox WHERE MailboxDisplayName = '" & strUserDisplayName & "'"
'WScript.Echo " DEBUG " & strWQL
WScript.Echo " Searching... Please wait"
Set wmiColl = wmiConn.ExecQuery(strWQL)
If wmiColl.Count >= 1 Then
' Get quota limits
if objResults.Fields("mDBUseDefaults").value = true then
Set mbstore = GetObject("GC://" & objResults.Fields("homemdb"))
if mbstore.mDBStorageQuota = "" then
strquota = "No Quota"
else
strquota = formatnumber(mbstore.mDBStorageQuota/1024,0)
end if
if mbstore.mDBOverQuotaLimit = "" then
stroverquota = "No Quota"
else
stroverquota = formatnumber(mbstore.mDBOverQuotaLimit/1024,0)
end if
if mbstore.mDBOverHardQuotaLimit = "" then
strHardLimit = "No Quota"
else
strHardLimit = formatnumber(mbstore.mDBOverHardQuotaLimit/1024,0)
end if
if strquota <> "No Quota" then
strquotasum = " Storage Quotas (Using store limits):" & vbcrlf
strquotasum = strquotasum & " Warning Limit: " & strquota & " MB" & vbcrlf
strquotasum = strquotasum & " Prohibit Send: " & stroverquota & " MB" & vbcrlf
strquotasum = strquotasum & " Prohibit Receive: " & strHardLimit & " MB" & vbcrlf
else
strquotasum = "Storage Limits: No Quotas Configured" & vbcrlf
end if
else
if isnull(objResults.fields("mDBStorageQuota").value) then
strquota = "No Quota"
else
strquota = formatnumber(objResults.fields("mDBStorageQuota").value/1024,0) & " MB"
end if
if isnull(objResults.fields("mDBOverQuotaLimit").value) then
stroverquota = "No Quota"
else
stroverquota = formatnumber(objResults.fields("mDBOverQuotaLimit").value/1024,0) & " MB"
end if
if isnull(objResults.fields("mDBOverHardQuotaLimit").value) then
strHardLimit = "No Quota"
else
strHardLimit = formatnumber(objResults.fields("mDBOverHardQuotaLimit").value/1024,0) & " MB"
end if
strquotasum = " Storage Quotas (Using custom limits):" & vbcrlf
strquotasum = strquotasum & " Warning Limit: " & strquota & vbcrlf
strquotasum = strquotasum & " Prohibit Send: " & stroverquota & vbcrlf
strquotasum = strquotasum & " Prohibit Receive: " & strHardLimit & vbcrlf
end if
' for each mailbox found (should only be one), display the size
For Each wmiObj In wmiColl
WScript.Echo " Found: " & wmiObj.MailboxDisplayName
WScript.Echo " Mailbox Size: " & formatnumber(wmiObj.Size/1024,1) & " MB" & vbCrLf
wscript.echo strquotasum
MsgBox " Mailbox: " & strUserDisplayName & vbcrlf & " Size: " & formatnumber(wmiObj.Size/1024,1) & _
" MB" & vbcrlf & vbcrlf & strquotasum, 0, "Search Results"
Next
Else
' No mailbox found
MsgBox "'" & strUserDisplayName & "' mailbox was not found on server " & strExchServer, 0, "Search Results"
End If
Set wmiColl = Nothing
Set wmiConn = Nothing
Else
WScript.Echo "* No Exchange Home Server defined for " & objResults.Fields("samAccountName").value & vbCrLf
End If
'move to the next record in the record set; quit when EOF is true
objResults.MoveNext
Loop until objResults.EOF
End If
Set objResults = Nothing
Set objADOCmd = Nothing
Set objADOCnxn = Nothing
WScript.Echo "Done!"
WScript.Quit
' Determines which program is used to run this script.
' Returns true if the script host is cscript.exe
Function IsHostCscript()
On Error Resume Next
Dim strFullName
Dim strCommand
Dim i, j
Dim bReturn
bReturn = False
strFullName = WScript.FullName
i = InStr(1, strFullName, ".exe", 1)
If i <> 0 Then
j = InStrRev(strFullName, "\", i, 1)
If j <> 0 Then
strCommand = Mid(strFullName, j+1, i-j-1)
If LCase(strCommand) = "cscript" Then
bReturn = True
End If
End If
End If
If Err <> 0 Then
Call WScript.echo("Error 0x" & Hex(Err.Number) & " occurred. " & Err.Description _
& ". " & vbCRLF & "The scripting host could not be determined.")
End If
IsHostCscript = bReturn
End Functionterça-feira, 30 de setembro de 2008 16:59 -
Opa amigo,
Cara tu precisa validar o script, faz um ambiente de lab eu so passei o olho e acho que ta okay, mas nao posso te confirmar um script a ser executado no teu ambiente.
Ve uma empresa da tua cidade para validar este script se realmente esta com duvidas, o primeiro e satisfatorio e a msexchange.org e uma fonte confiavel, mas vc precisa testar no teu ambiente, pedir para testar nos dos outros complcia
terça-feira, 30 de setembro de 2008 17:05
Todas as Respostas
-
Ola Amdkryn,
Via linha de comando tu vai ter que usar scrips e/ou wmi, e sem permissao, tu vai ter que pesquisar mais um pouco como fazer script ou achar uma ferramenta paga para isto, comece em www.msechange.org/software
terça-feira, 30 de setembro de 2008 13:36 -
Anderson,
Obrigado pela resposta, só que não faço idéia de como criar um script. Quanto a executar os comandos como adm, isso eu já tenho pronto, porque uso psexec, e consigo efetuar alguns mudanças nos logins, como bloquear, alterar senha, verificar inatividade....
Só preciso do comando para verificar se a caixa postal esta cheia, depois se possível, como eu poderia aumentar a caixa postal.
Vou verificar o site que recomendou: www.msexchange.org
Grato,terça-feira, 30 de setembro de 2008 15:02 -
Ola Amdrkyn,
Tu pode aumentar por usuario, iou ainda por mailbox store (ou seja todos usuarios contidos nele serao afetados), da uma procurada no script center, nao deve ter algo pronto mas bem proximo do que tu precisa, ai tu monta um frankstein script para a tua necessidade.
terça-feira, 30 de setembro de 2008 15:28 -
Pessoal,
Encontrei o seguinte artigo, que acredito que se adequa as minhas necessidades quanto a consulta do tamanho da caixa postal, mas esta tudo em inglês e não entendi muito bem.
Alguém pode esclarecer como faço para usar isso, por exemplo, onde determinado o meu servidor de e-mail?
Fonte: http://www.msexchange.org/articles/Scripting-Exchange-VBScript-ADSI-Part3.html
Getting Mailboxes Size
At this time (and this might change in the next Exchange version, E12), no single programming interface will cover Exchange. CDO is used to access Outlook items and can be used to get the mailbox size using MAPI, but it requires the user running the script to have access to all the mailboxes, a right denied by default in Exchange 2000/3 to Exchange administrators. However, this is the only method for Exchange 2000 servers. With Exchange 2003 server you can now retrieve the size of a mailbox using WMI. WMI you might ask? What? Now I have to learn another interface?
Microsoft developed WMI as a derivative of SNMP, a popular protocol that allows a single interface to monitor networking equipment. Any device that can communicate over the network and supports this protocol can provide information on network activity, CPU, memory and such. Microsoft extended this model to Windows applications and provided methods for not only retrieving information but also running application specific functions just like other programming interfaces can.
WMI has become quite popular with Microsoft, so almost every service pack and new version of any Microsoft server products expands the WMI interfaces available. However, new WMI interface are not added to old products, so you have WMI interfaces that exist for Exchange 2003 but not for Exchange 2000. One of these interfaces is the one that allows you to retrieve the size of a mailbox.
To access an application using WMI you require a CIM namespace, which defines the information available through the application.
On Error Resume Next
Dim cComputerName
Const cWMINameSpace = "root/MicrosoftExchangeV2"The rest of the script will fetch mailbox sizes for our server. Mailbox sizes are in Kilobytes.
Const cWMIInstance = "Exchange_Mailbox"
cComputerName = "EX2003" ' Modify this value to suit your serverDim strWinMgmts ' Connection string for WMI
Dim objWMIExchange ' Exchange Namespace WMI object
Dim listExchange_Mailboxs ' ExchangeLogons collection
Dim objExchange_Mailbox ' A single ExchangeLogon WMI object' Create the object string, indicating WMI (winmgmts), using the
' current user credentials (impersonationLevel=impersonate),
' on the computer specified in the constant cComputerName, and
' using the CIM namespace for the Exchange provider.
strWinMgmts = "winmgmts:{impersonationLevel=impersonate}!//"& _
cComputerName&"/"&cWMINameSpace
Set objWMIExchange = GetObject(strWinMgmts)
' Verify we were able to correctly set the object.
If Err.Number <> 0 Then
WScript.Echo "ERROR: Unable to connect to the WMI namespace."
Else
'
' The Resources that currently exist appear as a list of
' Exchange_Mailbox instances in the Exchange namespace.
Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance)
'
' Were any Exchange_Mailbox Instances returned?
If (listExchange_Mailboxs.count > 0) Then
' If yes, do the following:
' Iterate through the list of Exchange_Mailbox objects.
For Each objExchange_Mailbox in listExchange_Mailboxs
Wscript.Echo""
'
' Display the value of the Size property.
WScript.echo objExchange_Mailbox.MailboxDisplayName & "," & objExchange_Mailbox.Size
'
Next
Else
' If no Exchange_Mailbox instances were returned,
' display that.
WScript.Echo "WARNING: No Exchange_Mailbox instances were returned."
End If
End IfWMI can seem scary at first with its complex notation but you can always copy and paste existing scripts and modify them to suit your needs.
terça-feira, 30 de setembro de 2008 15:47 -
Opa,
Tu achou o script, salva ele em .vbs e manda ver, troca as variaveis para o teu ambiente e era isso.
para rodar tu pode rodar cscript teuscript.vbs
terça-feira, 30 de setembro de 2008 16:58 -
Encontrei o seguinte script, porém não sei exatamente oque será executado, devido a complexidade, alguém sabe me dizer se é seguro?
Fonte: http://www.flobee.net/?view=plink&id=114
Option Explicit
Dim objGC, objOU, strADPath
Dim strUserLoginName
Dim objADOCnxn, objADOCmd, strSearchFilter, strReturnAttrib, strSearchDepth, objResults, intMatchingRecords
Dim strUserDisplayName, strRawExchServer, strExchServer
Dim wmiConn, strWQL, wmiColl, wmiObj
Dim mbstore, strquota, stroverquota, strHardLimit, strmbsize, strquotasum
'
' Messages to be displayed if the scripting host is not cscript
'
Const kMessage1 = "Please run this script using CScript."
Const kMessage2 = "This can be achieved by"
Const kMessage3 = "1. Using ""CScript script.vbs arguments"" or"
Const kMessage4 = "2. Changing the default Windows Scripting Host to CScript"
Const kMessage5 = " using ""CScript //H:CScript //S"" and running the script "
Const kMessage6 = " ""script.vbs arguments""."
' Make sure running with CScript
If Not IsHostCscript() Then
Call WScript.echo(kMessage1 & vbCRLF & kMessage2 & vbCRLF & _
kMessage3 & vbCRLF & kMessage4 & vbCRLF & _
kMessage5 & vbCRLF & kMessage6 & vbCRLF)
WScript.quit
End If
' Connect to a global catalog for the forest
Set objGC = GetObject("GC:")
For Each objOU In objGC
strADPath = "<" & objOU.AdsPath & ">"
Next
Set objOU = Nothing
Set objGC = Nothing
WScript.Echo "* Searching within: " & strADPath
' Get input - strUserLoginName
strUserLoginName = InputBox("This will search for the user's mailbox and display its size." & _
vbCrLf & vbCrLf & "Enter a user's login name, or" & vbCrLf & "their primary SMTP address:" & _
vbCrLf & vbCrLf & "(LDAP wildcard characters are supported.)")
If strUserLoginName = "" Then
WScript.Echo "User Canceled"
WScript.Quit
End If
' Use ADO to query on the given user login name
Set objADOCnxn = CreateObject("ADODB.Connection")
objADOCnxn.Provider = "ADsDSOObject"
objADOCnxn.Open "Active Directory Provider"
Set objADOCmd = CreateObject("ADODB.Command")
objADOCmd.ActiveConnection = objADOCnxn
strSearchFilter ="(&(objectCategory=person)(|(mail=" & strUserLoginName & ")(samAccountName=" & strUserLoginName & ")))"
strReturnAttrib = "displayName,msExchHomeServerName,samAccountName,mdbUseDefaults,homemdb,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit"
strSearchDepth = "SubTree"
objADOCmd.CommandText = strADPath & ";" & strSearchFilter & ";" & strReturnAttrib & ";" & strSearchDepth
Set objResults = objADOCmd.Execute
intMatchingRecords = objResults.RecordCount
WScript.Echo " AD Search Returned " & intMatchingRecords & " Records" & vbCrLf
If intMatchingRecords < 1 Then
' User name was not found
MsgBox "The specified string was not found!" & vbCrLf & vbCrLf & "No matching user name or SMTP address(es)", 0, "Search Results"
Else
' We found a match, for each record in result set...
Do
strUserDisplayName = objResults.Fields("displayName").value
strRawExchServer = objResults.Fields("msExchHomeServerName").value
' only proceed if the msExchHomeServerName attribute contains an '=' character
If InStr(1, strRawExchServer, "=", vbTextCompare) Then
' Parse out the actual Exchange server name (everything to right of last '=')
strExchServer = Mid(strRawExchServer,InStrRev(strRawExchServer, "=", -1, vbTextCompare) + 1)
' Create a WMI connection to that server
Set wmiConn = GetObject("WinMgmts:{impersonationLevel=impersonate}!\\" & strExchServer & "\root\microsoftexchangev2")
' Search for the display name of the user
WScript.Echo "* Looking for '" & strUserDisplayName & "' on server " & strExchServer
strWQL = "SELECT * FROM Exchange_Mailbox WHERE MailboxDisplayName = '" & strUserDisplayName & "'"
'WScript.Echo " DEBUG " & strWQL
WScript.Echo " Searching... Please wait"
Set wmiColl = wmiConn.ExecQuery(strWQL)
If wmiColl.Count >= 1 Then
' Get quota limits
if objResults.Fields("mDBUseDefaults").value = true then
Set mbstore = GetObject("GC://" & objResults.Fields("homemdb"))
if mbstore.mDBStorageQuota = "" then
strquota = "No Quota"
else
strquota = formatnumber(mbstore.mDBStorageQuota/1024,0)
end if
if mbstore.mDBOverQuotaLimit = "" then
stroverquota = "No Quota"
else
stroverquota = formatnumber(mbstore.mDBOverQuotaLimit/1024,0)
end if
if mbstore.mDBOverHardQuotaLimit = "" then
strHardLimit = "No Quota"
else
strHardLimit = formatnumber(mbstore.mDBOverHardQuotaLimit/1024,0)
end if
if strquota <> "No Quota" then
strquotasum = " Storage Quotas (Using store limits):" & vbcrlf
strquotasum = strquotasum & " Warning Limit: " & strquota & " MB" & vbcrlf
strquotasum = strquotasum & " Prohibit Send: " & stroverquota & " MB" & vbcrlf
strquotasum = strquotasum & " Prohibit Receive: " & strHardLimit & " MB" & vbcrlf
else
strquotasum = "Storage Limits: No Quotas Configured" & vbcrlf
end if
else
if isnull(objResults.fields("mDBStorageQuota").value) then
strquota = "No Quota"
else
strquota = formatnumber(objResults.fields("mDBStorageQuota").value/1024,0) & " MB"
end if
if isnull(objResults.fields("mDBOverQuotaLimit").value) then
stroverquota = "No Quota"
else
stroverquota = formatnumber(objResults.fields("mDBOverQuotaLimit").value/1024,0) & " MB"
end if
if isnull(objResults.fields("mDBOverHardQuotaLimit").value) then
strHardLimit = "No Quota"
else
strHardLimit = formatnumber(objResults.fields("mDBOverHardQuotaLimit").value/1024,0) & " MB"
end if
strquotasum = " Storage Quotas (Using custom limits):" & vbcrlf
strquotasum = strquotasum & " Warning Limit: " & strquota & vbcrlf
strquotasum = strquotasum & " Prohibit Send: " & stroverquota & vbcrlf
strquotasum = strquotasum & " Prohibit Receive: " & strHardLimit & vbcrlf
end if
' for each mailbox found (should only be one), display the size
For Each wmiObj In wmiColl
WScript.Echo " Found: " & wmiObj.MailboxDisplayName
WScript.Echo " Mailbox Size: " & formatnumber(wmiObj.Size/1024,1) & " MB" & vbCrLf
wscript.echo strquotasum
MsgBox " Mailbox: " & strUserDisplayName & vbcrlf & " Size: " & formatnumber(wmiObj.Size/1024,1) & _
" MB" & vbcrlf & vbcrlf & strquotasum, 0, "Search Results"
Next
Else
' No mailbox found
MsgBox "'" & strUserDisplayName & "' mailbox was not found on server " & strExchServer, 0, "Search Results"
End If
Set wmiColl = Nothing
Set wmiConn = Nothing
Else
WScript.Echo "* No Exchange Home Server defined for " & objResults.Fields("samAccountName").value & vbCrLf
End If
'move to the next record in the record set; quit when EOF is true
objResults.MoveNext
Loop until objResults.EOF
End If
Set objResults = Nothing
Set objADOCmd = Nothing
Set objADOCnxn = Nothing
WScript.Echo "Done!"
WScript.Quit
' Determines which program is used to run this script.
' Returns true if the script host is cscript.exe
Function IsHostCscript()
On Error Resume Next
Dim strFullName
Dim strCommand
Dim i, j
Dim bReturn
bReturn = False
strFullName = WScript.FullName
i = InStr(1, strFullName, ".exe", 1)
If i <> 0 Then
j = InStrRev(strFullName, "\", i, 1)
If j <> 0 Then
strCommand = Mid(strFullName, j+1, i-j-1)
If LCase(strCommand) = "cscript" Then
bReturn = True
End If
End If
End If
If Err <> 0 Then
Call WScript.echo("Error 0x" & Hex(Err.Number) & " occurred. " & Err.Description _
& ". " & vbCRLF & "The scripting host could not be determined.")
End If
IsHostCscript = bReturn
End Functionterça-feira, 30 de setembro de 2008 16:59 -
Opa amigo,
Cara tu precisa validar o script, faz um ambiente de lab eu so passei o olho e acho que ta okay, mas nao posso te confirmar um script a ser executado no teu ambiente.
Ve uma empresa da tua cidade para validar este script se realmente esta com duvidas, o primeiro e satisfatorio e a msexchange.org e uma fonte confiavel, mas vc precisa testar no teu ambiente, pedir para testar nos dos outros complcia
terça-feira, 30 de setembro de 2008 17:05 -
Rsrssrsrs, não precisa testar no dos outros......
Eu me viro, a dúvida era só pra saber se o script tem alguma instrução de inclusão;
Muito obrigado pela ajuda.
T+terça-feira, 30 de setembro de 2008 19:02 -
Ola Amdkryn,
Procura por set, add que sao as principais causas de inclusao e remoçao de dados via vbscript.
So marca os post que te ajudarm a chegar na conlusao, ou ainda, mais proximo dela.
Abracao e boa sorte ai,
terça-feira, 30 de setembro de 2008 19:04