Top-Themen

AppleEntwicklungHardwareInternetLinuxMicrosoftMultimediaNetzwerkeOff TopicSicherheitSonstige SystemeVirtualisierungWeiterbildungZusammenarbeit

Aktuelle Themen

Administrator.de FeedbackApache ServerAppleAssemblerAudioAusbildungAuslandBackupBasicBatch & ShellBenchmarksBibliotheken & ToolkitsBlogsCloud-DiensteClusterCMSCPU, RAM, MainboardsCSSC und C++DatenbankenDatenschutzDebianDigitiales FernsehenDNSDrucker und ScannerDSL, VDSLE-BooksE-BusinessE-MailEntwicklungErkennung und -AbwehrExchange ServerFestplatten, SSD, RaidFirewallFlatratesGoogle AndroidGrafikGrafikkarten & MonitoreGroupwareHardwareHosting & HousingHTMLHumor (lol)Hyper-VIconsIDE & EditorenInformationsdiensteInstallationInstant MessagingInternetInternet DomäneniOSISDN & AnaloganschlüsseiTunesJavaJavaScriptKiXtartKVMLAN, WAN, WirelessLinuxLinux DesktopLinux NetzwerkLinux ToolsLinux UserverwaltungLizenzierungMac OS XMicrosoftMicrosoft OfficeMikroTik RouterOSMonitoringMultimediaMultimedia & ZubehörNetzwerkeNetzwerkgrundlagenNetzwerkmanagementNetzwerkprotokolleNotebook & ZubehörNovell NetwareOff TopicOpenOffice, LibreOfficeOutlook & MailPapierkorbPascal und DelphiPeripheriegerätePerlPHPPythonRechtliche FragenRedHat, CentOS, FedoraRouter & RoutingSambaSAN, NAS, DASSchriftartenSchulung & TrainingSEOServerServer-HardwareSicherheitSicherheits-ToolsSicherheitsgrundlagenSolarisSonstige SystemeSoziale NetzwerkeSpeicherkartenStudentenjobs & PraktikumSuche ProjektpartnerSuseSwitche und HubsTipps & TricksTK-Netze & GeräteUbuntuUMTS, EDGE & GPRSUtilitiesVB for ApplicationsVerschlüsselung & ZertifikateVideo & StreamingViren und TrojanerVirtualisierungVisual StudioVmwareVoice over IPWebbrowserWebentwicklungWeiterbildungWindows 7Windows 8Windows 10Windows InstallationWindows MobileWindows NetzwerkWindows ServerWindows SystemdateienWindows ToolsWindows UpdateWindows UserverwaltungWindows VistaWindows XPXenserverXMLZusammenarbeit

Exchange 2003 Mailbox Report

Frage Microsoft Exchange Server

Mitglied: Computernoob

Computernoob (Level 1) - Jetzt verbinden

17.10.2012, aktualisiert 11:38 Uhr, 1815 Aufrufe

Hallo Kollegen,

ich hab ein kleines Problem mit folgendem Script:

Und zwar sollte es mir eigentlich einen Exchange 2003 Mailbox Report in eine *:csv erstellen, jedoch bleiben die Werte wie z.B. "Größe, Name" leer.

Der Exchange-Server wird aber vom Script gefunden.

System:
Windows Server 2003
Exchange 2003

Ich hoffe Ihr könnt mir helfen.


Der Script wird so ausgeführt: cscript //NoLogo ExchMailBoxStats.vbs

01.
Option Explicit  
02.
  
03.
Dim sOutputFile: sOutputFile = OutputFileName()  
04.
WScript.Echo Now & " - Starting " & WScript.ScriptName & " script"  
05.
Dim arrServerNames: arrServerNames = Split (GetExchangeServers (), ",") 
06.
Dim dicStores: Set dicStores = CreateObject("Scripting.Dictionary"): dicStores.CompareMode = 1  
07.
CreateStoresDictionary  
08.
CreateMailboxStatsReport  
09.
WScript.Echo "Mailbox Statistics Report completed: " & sOutputFile  
10.
WScript.Echo Now & " - " & WScript.ScriptName & " finished!"  
11.
  
12.
  
13.
Function OutputFileName()  
14.
    OutputFileName = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName)-3) & _  
15.
        ReverseDate() & ".csv"  
16.
End Function  
17.
  
18.
Function ReverseDate()  
19.
    Dim dt: dt = date(): dt = Year(dt)*1e4 + Month(dt)*1e2 + Day(dt)  
20.
    ReverseDate = dt  
21.
End Function  
22.
  
23.
Sub AppendToLog(sData)  
24.
    With CreateObject("Scripting.FileSystemObject")._  
25.
        OpenTextFile(sOutputFile, 8, True)  
26.
        .Write sData & vbNewLine: .Close  
27.
    End With   
28.
End Sub  
29.
  
30.
Function GetExchangeServers()  
31.
    Dim oConn, oCmd, oRs  
32.
    Dim sCNC, sFilter, sQuery, sOutput  
33.
    Set oConn = Createobject("ADODB.Connection")  
34.
    Set oCmd = Createobject("ADODB.Command")  
35.
    Set oRs = Createobject("ADODB.Recordset")  
36.
    sCNC = "CN=Microsoft Exchange,CN=Services," & _  
37.
                    GetObject("LDAP://RootDSE").Get("configurationNamingContext")  
38.
    sFilter = "(&(objectCategory=msExchExchangeServer)(objectClass=msExchExchangeServer))"  
39.
    sQuery = "<LDAP://" & sCNC & ">;" & sFilter & ";name;subtree"  
40.
    oConn.Provider = "ADsDSOObject"  
41.
    oConn.Open "ADs Provider"  
42.
    Wscript.Echo "Querying ActiveDirectory for Exchange Servers..."  
43.
    oCmd.ActiveConnection = oConn  
44.
    oCmd.CommandText = sQuery  
45.
    Set oRs = oCmd.Execute  
46.
    While Not oRs.EOF  
47.
        sOutput = sOutput & oRs.Fields("name") & ","  
48.
        oRs.MoveNext  
49.
    Wend  
50.
    If Right(sOutput,1) = "," Then sOutput = Left(sOutput,(Len(sOutput))-1)  
51.
    WScript.Echo "Exchange Servers found in ActiveDirectory: " & sOutput  
52.
    oRs.Close(): Set oRs = Nothing  
53.
    Set oCmd = Nothing  
54.
    oConn.Close(): Set oConn = Nothing  
55.
    GetExchangeServers = sOutput  
56.
End Function  
57.
  
58.
Sub CreateStoresDictionary  
59.
    Dim sCNC, sQuery, sFilter  
60.
    Dim sStoreNameDictEntry, sStorePolicyDictEntry, oPolicy, sPolicyDN  
61.
    sCNC = "CN=Microsoft Exchange,CN=Services," & _  
62.
                GetObject("LDAP://RootDSE").Get("configurationNamingContext")  
63.
    Dim oConn: Set oConn = CreateObject("ADODB.Connection")  
64.
    oConn.Provider = "ADsDSOObject"  
65.
    oConn.Open "Active Directory Provider"  
66.
    Dim oCmd: Set oCmd = CreateObject("ADODB.Command")  
67.
    oCmd.ActiveConnection = oConn  
68.
    oCmd.Properties("page size") = 15000  
69.
    sFilter = "(&(objectClass=msExchPrivateMDB)(!objectClass=msExchPrivateMDBPolicy))"  
70.
    sQuery = "<LDAP://" & sCNC & ">;" & _  
71.
        sFilter & ";cn,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit;subtree"  
72.
    oCmd.CommandText = sQuery  
73.
    oCmd.Properties("Page Size") = 15000  
74.
    oCmd.Properties("Timeout") = 90  
75.
    WScript.Echo "Querying Exchange Information Stores Quota Settings..."  
76.
    Dim oRs: Set oRs = Createobject("ADODB.Recordset")  
77.
    Set oRs = oCmd.Execute  
78.
    If oRs.RecordCount > 0 Then  
79.
        oRs.MoveFirst  
80.
        Do Until oRs.EOF  
81.
              sStoreNameDictEntry = oRs.Fields("cn")  
82.
  
83.
            If IsNull(oRs.Fields("mDBStorageQuota")) Then  
84.
                sStorePolicyDictEntry = "Unlimited,"  
85.
            Else  
86.
                sStorePolicyDictEntry = ReportSize(oRs.Fields("mDBStorageQuota")) & ","  
87.
            End If  
88.
                  
89.
            If IsNull(oRs.Fields("mDBOverQuotaLimit")) Then  
90.
                sStorePolicyDictEntry = sStorePolicyDictEntry & "Unlimited,"  
91.
            Else  
92.
                sStorePolicyDictEntry = sStorePolicyDictEntry & ReportSize(oRs.Fields("mDBOverQuotaLimit")) & ","  
93.
            End If  
94.
              
95.
            If IsNull(oRs.Fields("mDBOverHardQuotaLimit")) Then  
96.
                sStorePolicyDictEntry = sStorePolicyDictEntry & "Unlimited,"  
97.
            Else  
98.
                sStorePolicyDictEntry = sStorePolicyDictEntry & ReportSize(oRs.Fields("mDBOverHardQuotaLimit")) & ","  
99.
            End If  
100.
              
101.
            sStorePolicyDictEntry = sStorePolicyDictEntry & "Mailbox Store"  
102.
            If Not dicStores.Exists(sStoreNameDictEntry) Then _  
103.
                dicStores.Add sStoreNameDictEntry, sStorePolicyDictEntry  
104.
            oRs.MoveNext  
105.
        Loop  
106.
    End If  
107.
    oRs.Close(): Set oRs = Nothing  
108.
    Set oCmd = Nothing  
109.
    oConn.Close(): Set oConn = Nothing  
110.
End Sub  
111.
  
112.
  
113.
Sub CreateMailboxStatsReport  
114.
    On Error Resume Next  
115.
    Dim sServer, oWMIExchange, oMailboxes, oMailbox, sOutLine  
116.
    If UBound(arrServerNames) >= 0 Then  
117.
        AppendToLog "Account Name,User Principal Name,Display Name,EMail,Issue Warning,Prohibit Send,Prohibit Send and Receive,Quota Set Level,Limit Status,Mailbox Size,Total Items,Mailbox Location"  
118.
        WScript.Echo "Querying Exchange Servers For Mailboxes..."  
119.
        For Each sServer in arrServerNames  
120.
            Set oWMIExchange = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & _  
121.
                                sServer & "/root/MicrosoftExchangeV2")  
122.
            If Err.Number = 0 Then  
123.
                WScript.Echo "Unable to connect to the " & sServer & _  
124.
                    "/root/MicrosoftExchangeV2 namespace."  
125.
            Else  
126.
                Set oMailboxes = oWMIExchange.ExecQuery("SELECT * FROM Exchange_Mailbox WHERE NOT LegacyDN LIKE '%SYSTEMMAILBOX%' AND NOT LegacyDN LIKE '%CN=CONFIGURATION/%'")  
127.
                If (oMailboxes.count > 0) Then  
128.
                    For Each oMailbox in oMailboxes  
129.
                        If oMailbox.DateDiscoveredAbsentInDS <> "" Then  
130.
                            sOutLine = "[Disconnected Mailbox],N/A,N/A,N/A,N/A,N/A,N/A,N/A," & _  
131.
                                        LimitStatus(oMailbox.StorageLimitInfo) & "," & ReportSize(oMailbox.Size) & "," & oMailbox.TotalItems & "," & _  
132.
                                            oMailbox.ServerName & "\" & oMailbox.StorageGroupName &  "\" & oMailbox.StoreName & "\" & oMailbox.MailboxDisplayName  
133.
                        Else  
134.
                            sOutLine = GetMailboxStatsFromAD(oMailbox.LegacyDN) & "," & _  
135.
                                        LimitStatus(oMailbox.StorageLimitInfo) & "," & ReportSize(oMailbox.Size) & "," & oMailbox.TotalItems & "," & _  
136.
                                            oMailbox.ServerName & "\" & oMailbox.StorageGroupName &  "\" & oMailbox.StoreName & "\" & oMailbox.MailboxDisplayName  
137.
                        End If  
138.
                        AppendToLog sOutLine  
139.
                      Next  
140.
                End If  
141.
                Set oMailbox = Nothing  
142.
                Set oMailboxes = Nothing  
143.
            End If  
144.
        Next  
145.
        Set oWMIExchange = Nothing  
146.
    Else  
147.
        WScript.Echo "No Exchange Servers found in ActiveDirectory"  
148.
    End If  
149.
End Sub  
150.
  
151.
  
152.
Function GetMailboxStatsFromAD(legacyExchangeDN)  
153.
    Dim sRootDSE, sQuery, sFilter, sFields, sRet, sHomeMDBCn  
154.
    Dim sSamAccountName, sUserPrincipalName, sDisplayName, sMail, sQuota  
155.
    sRootDSE = GetObject("LDAP://rootDSE").Get("defaultNamingContext")  
156.
    Dim oConn: Set oConn = CreateObject("ADODB.Connection")  
157.
    oConn.Provider = "ADsDSOObject"  
158.
    oConn.Open "Active Directory Provider"  
159.
    Dim oCmd: Set oCmd = CreateObject("ADODB.Command")  
160.
    oCmd.ActiveConnection = oConn  
161.
    oCmd.Properties("page size") = 15000  
162.
    sFilter = "(&(ObjectClass=user)(ObjectCategory=person)(legacyExchangeDN=" & legacyExchangeDN & "))"  
163.
    sFields = "samAccountName,userPrincipalName,displayName,mail,mDBUseDefaults,mDBStorageQuota,mDBOverQuotaLimit,mDBOverHardQuotaLimit,homeMDB"  
164.
    sQuery = "<LDAP://" & sRootDSE & ">;" & sFilter & ";" & sFields & ";subtree"  
165.
    oCmd.CommandText = sQuery  
166.
    oCmd.Properties("Page Size") = 15000  
167.
    oCmd.Properties("Timeout") = 90  
168.
    Dim oRs: Set oRs = Createobject("ADODB.Recordset")  
169.
    Set oRs = oCmd.Execute  
170.
    If oRs.RecordCount > 0 Then  
171.
        oRs.MoveFirst  
172.
        Do Until oRs.EOF  
173.
                  
174.
            If IsNull(oRs.Fields("samAccountName")) Then  
175.
                sSamAccountName = "N/A"  
176.
            Else  
177.
                sSamAccountName = oRs.Fields("samAccountName")  
178.
            End If  
179.
              
180.
            If IsNull(oRs.Fields("userPrincipalName")) Then  
181.
                sUserPrincipalName = "N/A"  
182.
            Else  
183.
                sUserPrincipalName = oRs.Fields("userPrincipalName")  
184.
            End If  
185.
              
186.
            If IsNull(oRs.Fields("displayName")) Then  
187.
                sDisplayName = "N/A"  
188.
            Else  
189.
                sDisplayName = Trim(oRs.Fields("displayName"))  
190.
            End If  
191.
              
192.
            If IsNull(oRs.Fields("mail")) Then  
193.
                sMail = "N/A"  
194.
            Else  
195.
                sMail = oRs.Fields("mail")  
196.
            End If  
197.
              
198.
            sRet = sSamAccountName & "," & sUserPrincipalName & "," & _  
199.
                    sDisplayName & "," & sMail  
200.
  
201.
            If Not CBool(oRs.Fields("mDBUseDefaults")) Then  
202.
                If IsNull(oRs.Fields("mDBStorageQuota")) Then  
203.
                    sQuota = "Unlimited"  
204.
                Else  
205.
                    sQuota = ReportSize(oRs.Fields("mDBStorageQuota"))  
206.
                End If  
207.
                  
208.
                If IsNull(oRs.Fields("mDBOverQuotaLimit")) Then  
209.
                    sQuota = sQuota & "," & "Unlimited"  
210.
                Else  
211.
                    sQuota = sQuota & "," & ReportSize(oRs.Fields("mDBOverQuotaLimit"))  
212.
                End If  
213.
                  
214.
                If IsNull(oRs.Fields("mDBOverHardQuotaLimit")) Then  
215.
                    sQuota = sQuota & "," & "Unlimited"  
216.
                Else  
217.
                    sQuota = sQuota & "," & ReportSize(oRs.Fields("mDBOverHardQuotaLimit"))  
218.
                End If  
219.
                  
220.
                sRet = sRet & "," & sQuota & ",User"  
221.
            Else  
222.
                sHomeMDBCn = GetObject("LDAP://" & oRs.Fields("homeMDB")).cn  
223.
                If dicStores.Exists(sHomeMDBCn) Then  
224.
                    sRet = sRet & "," & dicStores.Item(sHomeMDBCn)  
225.
                Else  
226.
                    sRet = sRet & ",UnKnown,UnKnown,UnKnown,UnKnown"  
227.
                End If  
228.
            End If  
229.
            oRs.MoveNext  
230.
        Loop  
231.
    End If  
232.
    oRs.Close(): Set oRs = Nothing  
233.
    Set oCmd = Nothing  
234.
    oConn.Close(): Set oConn = Nothing  
235.
    GetMailboxStatsFromAD = sRet  
236.
End Function  
237.
  
238.
  
239.
Function ReportSize(iSize)  
240.
    Dim sUnit, i: i = 0  
241.
    While iSize > 1000  
242.
        iSize = Round(((iSize)/1024),2)  
243.
        i = i + 1  
244.
    Wend  
245.
    Select Case i  
246.
        Case 0: sUnit = " KB"  
247.
        Case 1: sUnit = " MB"  
248.
        Case 2: sUnit = " GB"  
249.
        Case 3: sUnit = " TB"  
250.
        Case 4: sUnit = " PB"  
251.
    End Select  
252.
    ReportSize = iSize & sUnit  
253.
End Function  
254.
  
255.
  
256.
Function LimitStatus(iStatus)  
257.
    Dim sRet: sRet = "UnKnown"  
258.
    Select Case iStatus  
259.
        Case 1: sRet = "Below Limit"  
260.
        Case 2: sRet = "Issue Warning"  
261.
        Case 4: sRet = "Prohibit Send"  
262.
        Case 8: sRet = "No Checking"  
263.
        Case 16: sRet = "Mailbox Disabled"  
264.
        Case Else: sRet= "UnKnown"  
265.
    End Select  
266.
    LimitStatus = sRet  
267.
End Function
Neuester Wissensbeitrag
Windows 10

Powershell 5 BSOD

(8)

Tipp von agowa338 zum Thema Windows 10 ...

Ähnliche Inhalte
Exchange Server
Exchange 2003 auf 2007 Implace Migration (18)

Frage von Herbrich19 zum Thema Exchange Server ...

Exchange Server
gelöst Exchange 2003 von Windows 2003 Server lösen bzw. entfernen (3)

Frage von plexxus zum Thema Exchange Server ...

Exchange Server
Office 2013 oder 2016 mit Exchange 2003 (2)

Frage von uridium69 zum Thema Exchange Server ...

Exchange Server
Exchange 2003 für Experimente noch nutzbar? (14)

Frage von pelzfrucht zum Thema Exchange Server ...

Heiß diskutierte Inhalte
Microsoft
Ordner mit LW-Buchstaben versehen und benennen (21)

Frage von Xaero1982 zum Thema Microsoft ...

Netzwerkmanagement
gelöst Anregungen, kleiner Betrieb, IT-Umgebung (18)

Frage von Unwichtig zum Thema Netzwerkmanagement ...

Windows Update
Treiberinstallation durch Windows Update läßt sich nicht verhindern (17)

Frage von liquidbase zum Thema Windows Update ...