|
Here
it is. I do not pretend to be the scripting guru's that many of you are...
rewriting with LDAP would prolly be much more efficient - but I'm not that
good.
And I
will point out that this displays a bug in ADSI (CDO?) -- if
objUser.mailNickname has an '@' in it - the ADO query
will fail.
Option
Explicit
'On
Error Resume Next
Dim
oRootDSE ' (ActiveDs.IADs) directory services root object
Dim varDomainNC ' (Variant) the domain naming context, will be a string of the form "DC=brnets,DC=int" Dim varConfigNC ' (Variant) the configuration naming context, will be a string of the form "CN=Configuration,DC=brnets,DC=int" Dim strErr ' global error string Dim strOrgCN ' organization common name Dim strOrgDN ' organization distinguished name Dim strDefault ' default domain name from Exchange's Default Recipient Policy Sub
GetStartupInfo()
Dim Conn ' As New ADODB.Connection Dim Com ' As New ADODB.Command Dim Rs ' As ADODB.Recordset Dim strQuery ' As String Dim i Dim obj, subobj ' Get the configuration naming
context.
Set oRootDSE = GetObject("LDAP://RootDSE") varConfigNC = oRootDSE.Get ("configurationNamingContext") varDomainNC = oRootDSE.Get ("defaultNamingContext") 'wscript.echo "Configuration Naming Context: " &
varConfigNC
'wscript.echo "Domain Naming Context: " & varDomainNC set Conn = Wscript.CreateObject
("ADODB.Connection")
set Com = Wscript.CreateObject ("ADODB.Command") ' Open the connection.
Conn.Provider = "ADsDSOObject" Conn.Open "ADs Provider" ' Build the query to find the
organization.
strQuery = "<LDAP://" & varConfigNC & ">;(objectCategory=msExchOrganizationContainer);name,cn,distinguishedName;subtree" Com.ActiveConnection = Conn
Com.CommandText = strQuery Set Rs = Com.Execute strOrgCN = ""
strOrgDN = "" ' Iterate through the results.
While Not Rs.EOF ' Output the name of the organization. 'wscript.Echo "Org CN: " & Rs.Fields ("cn") 'wscript.Echo "Org Name: " & Rs.Fields ("name") 'wscript.Echo "Org DN: " & Rs.Fields ("distinguishedName") strOrgCN = Rs.Fields ("cn") strOrgDN = Rs.Fields ("distinguishedName") Rs.MoveNext Wend ' Done with querying LDAP
Rs.Close Conn.Close set Rs = Nothing set Com = Nothing set Conn = Nothing If Len (strOrgDN) = 0 Then
Wscript.Echo "Cannot continue - cannot find organization distinguished name" Wscript.Quit (1) End If strDefault = ""
Set obj = GetObject ("LDAP://CN=Default Policy,CN=Recipient Policies," + strOrgDN) subobj = obj.Get ("gatewayProxy") For Each i In subobj If Left (i, 4) = "SMTP" Then 'wscript.Echo "Default follows" strDefault = Right (i, Len(i) - 6) ' strip SMTP:@ End If 'wscript.echo i Next Set subobj = Nothing
Set obj = Nothing If Len (strDefault) = 0 Then
Wscript.Echo "Cannot continue - cannot find default SMTP domain" Wscript.Quit (1) End If End Sub Function GetMailboxSize (strMailBoxName,
strDomainName)
Dim sDomainName ' As String Dim sUserName ' As String Dim mailboxSZ ' As Double Dim sURL ' As String Dim sSQL ' As String Dim Rs ' As New ADODB.Recordset Dim Rec ' As New ADODB.Record Dim i On Error Resume Next set Rs = Wscript.CreateObject
("ADODB.Recordset")
set Rec = Wscript.CreateObject ("ADODB.Record") mailboxSZ = 0
'i = Instr (1, strMailBoxName,
"@")
i = 0 If i > 0 Then sUserName = Left (strMailBoxName, i - 1) Else sUsername = strMailBoxName End If sURL = "file://./backofficestorage/" &
strDomainName & "/MBX/" & sUserName
'wscript.echo sURL Rec.Open sURL
If Err.Number <> 0 Then strErr = "Could not open: " & sURL & " (" & err.Description & ")" GetMailboxSize = -1 Exit Function End If sSQL = "Select" sSQL = sSQL & " ""http://schemas.microsoft.com" & _ "/exchange/foldersize"" " sSQL = sSQL & ", ""DAV:displayname"" " sSQL = sSQL & " from scope ('deep traversal of " & Chr(34) sSQL = sSQL & sURL & Chr(34) & "')" sSQL = sSQL & "Where ""DAV:isfolder""=true" Rs.Open sSQL, Rec.ActiveConnection If Not Rs.EOF Then Rs.MoveFirst End If While Not Rs.EOF 'Uncomment the following lines if you would like to 'see the size of each folder 'Wscript.echo Rs.Fields("DAV:displayname").Value & " " & _ ' Rs.Fields("http://schemas.microsoft.com/exchange/foldersize").Value mailboxSZ = mailboxSZ + _ Rs.Fields("http://schemas.microsoft.com/exchange/foldersize").Value Rs.MoveNext Wend 'Wscript.echo "Mailbox: " & strMailBoxName & " size: " & mailboxSZ & " bytes" GetMailboxSize = mailboxSZ Rs.Close Rec.Close set Rs = Nothing
set Rec = Nothing End Function Function List_Users (DomainName, exchDomainName)
' Example: Call List_users ("CN=Users,DC=brnets,DC=int", "brnets.com") Dim objUser ' As IADsUser Dim objContainer ' As IADsContainer Dim objMailbox ' As CDOEXM.IMailboxStore Dim objR Dim i ' As Long Dim inx ' As Long Dim sz ' As Double Dim name ' As String Dim obj1, obj2, obj3 ' get the container. Note that user information may be
located in
' other organizational units. Set objContainer = GetObject("LDAP://" + DomainName) objContainer.Filter =
Array("User")
i = 0 For Each objUser In
objContainer
name = objUser.name 'wscript.echo "name: " & name & " upn: " & objUser.UserPrincipalName & " sam: " & objUser.samAccountName name = Right(name, Len(name) - 3) Set objMailbox = objUser If objMailbox.HomeMDB = "" Then 'Wscript.echo name + " (no mailbox)" Else 'Wscript.echo name + " (has mailbox)" 'Wscript.echo objMailbox.HomeMDB sz = GetMailboxSize (objUser.mailNickname, exchDomainName) If sz < 0 Then WScript.Echo strErr Else WScript.Echo name & " (" & objUser.mailNickname & ") has a mailbox of " & _ FormatNumber (sz, 0) & " bytes" End If ' email addresses ' Set objR = objUser ' For inx = LBound(objR.ProxyAddresses) To UBound(objR.ProxyAddresses) ' obj1 = objR.ProxyAddresses ' for each obj2 in obj1 ' Wscript.echo obj2 ' next ' Next End
If
i = i + 1 Next 'Wscript.echo "Number of users found in " &
DomainName & ": " & i
End Function Call
GetStartupInfo()
Call List_Users ("CN=Users," + varDomainNC,
strDefault)
Call List_Users ("OU=PBM Temporary OU," + varDomainNC, strDefault) Call List_Users ("OU=domain.com,OU=Hosting," + varDomainNC, strDefault) . .
.
|
Title: Message
- [ActiveDir] Exchange 2000 question Rick Reynolds
- RE: [ActiveDir] Exchange 2000 question Mulnick, Al
- RE: [ActiveDir] Exchange 2000 question Shawn.Hayes
- RE: [ActiveDir] Exchange 2000 question Joe Pochedley
- RE: [ActiveDir] Exchange 2000 question Michael B. Smith
- RE: [ActiveDir] Exchange 2000 question Craig Cerino
- RE: [ActiveDir] Exchange 2000 question Michael B. Smith
