|
From: simalt on 4 Jun 2008 07:23 Could someone help me with this please. This puts out a list of mailboxes from each server to a text file with tabs. Is it possible to change this to comma delimited. Thanks. 'To list the largest mailbox on each server Option Explicit '**** '* Purpose: Display each Exchange_Mailbox found for Exchange server, '* and show selected, formated properties on the '* Exchange_Mailbox objects '* Change: cComputerName [string] the computer to access (netbios name) '* Output: Displays the name of each Exchange_Mailbox and properties '* '* based on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3... wmiref_cl_Exchange_Mailbox.asp '* works only with Exchange 2003 servers '**** '* Const cServerNames = "c:\Scripts\serverNames.txt" Const cWinMgmts = "winmgmts:{impersonationLevel=impersonate}!\ \" Const cWMINameSpace = "root/MicrosoftExchangeV2" Const cWMIInstance = "Exchange_Mailbox" Const cBOX = "OctelVMD,SMTP,System Attendant,SystemMailbox" Const cDBG = False '= Debug flag (Ture/False) '* Dim i, j, k Dim arrBOX arrBOX = Split(cBOX,",") Dim booBOX Dim intBOX Dim strBOX Dim intLEN intLEN = 0 Dim arrOUT() Dim intOUT intOUT = 0 Dim strOUT Dim strTMP Dim strTXT '* Dim strWinMgmts ' Connection string for WMI Dim objWMIExchange ' Exchange Namespace WMI object Dim listExchange_Mailboxes ' Exchange_Mailbox collection Dim objExchange_Mailbox ' A single Exchange_Mailbox WMI object Dim cComputerName Dim fileSys Set fileSys = CreateObject("Scripting.FileSystemObject") Dim fileToRead Set fileToRead = fileSys.OpenTextFile(cServerNames,1) '* '* 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. '* '- Do While fileToRead.AtEndOfStream <> True Do While Not fileToRead.AtEndOfStream cComputerName = fileToRead.ReadLine If cComputerName = "" Then Exit Do WScript.Echo "Server name is: " & cComputerName strWinMgmts = cWinMgmts & cComputerName & "\" & cWMINameSpace '* On Error Resume Next Set objWMIExchange = GetObject(strWinMgmts) '* '* Verify connection to the WMI namespace on the server '* If Err.Number <> 0 Then WScript.Echo "ERROR: Unable to connect to the WMI namespace." WScript.Echo Err.Description & " (" & Hex(Err.Number) & ")" WScript.Quit 1 End If On Error GoTo 0 '* '* The Resources that currently exist appear as a list of '* Exchange_Mailbox instances in the Exchange namespace. '* Set listExchange_Mailboxes = objWMIExchange.InstancesOf(cWMIInstance) '* '* Were any Exchange_Mailbox Instances returned? '* If listExchange_Mailboxes.count <= 0 Then WScript.Echo "WARNING: No Exchange_Mailbox instances were returned." WScript.Quit 1 End If '* WScript.Echo "Running mailbox size report for all stores on server " & cComputerName & vbCrLf '* '* Iterate through the list of Exchange_Mailbox objects. '* If cDBG Then WScript.Echo "Loop!" For Each objExchange_Mailbox in listExchange_Mailboxes If cDBG Then WScript.Echo ".LegacyDN = " _ & objExchange_Mailbox.LegacyDN _ & vbTab & ".MailboxDisplayName = " _ & objExchange_Mailbox.MailboxDisplayName _ & vbTab & ".Size = " _ & objExchange_Mailbox.Size _ & vbTab & ".TotalItems = " _ & objExchange_Mailbox.TotalItems strTMP = objExchange_Mailbox.LegacyDN strTMP = Mid(strTMP,InStrRev(strTMP,"CN=")+3) strTMP = objExchange_Mailbox.MailboxDisplayName & " (" & strTMP & ")" If intLEN < Len(strTMP) Then intLEN = Len(strTMP) ReDim Preserve arrOUT(intOUT) arrOUT(intOUT) = (10^10-objExchange_Mailbox.Size) _ & vbtab & strTMP _ & vbtab & FormatNumber(objExchange_Mailbox.Size,0) _ & vbtab & FormatNumber(objExchange_Mailbox.TotalItems, 0) If cDBG Then WScript.Echo intOUT & ". " & arrOUT(intOUT) intOUT = intOUT + 1 Next Set objWMIExchange = Nothing '* '* Sort by objExchange_Mailbox.Size '* If cDBG Then WScript.Echo "Sort!" For i = UBound(arrOUT) - 1 To 0 Step -1 For j = 0 To i If arrOUT(j) > arrOUT(j+1) Then k = arrOUT(j+1) arrOUT(j+1) = arrOUT(j) arrOUT(j) = k End If Next Next '* '* List by objExchange_Mailbox.Size '* If cDBG Then WScript.Echo "List!" strTXT = "Mailbox" & Space(intLEN-7) _ & " Size" _ & " Items" WScript.Echo strTXT & vbCrLf & String(intLEN+12+10,"-") For intOUT = 0 To UBound(arrOUT) strOUT = Split(arrOUT(intOUT),vbTab) '* booBOX = True For intBOX = 0 To UBound(arrBOX) strBOX = arrBOX(intBOX) If InStr(strOUT(1),strBOX) > 0 Then booBOX = False Next '* If booBOX Then strTXT = strOUT(1) & Space(intLEN-Len(strOUT(1))) _ & Space(12-Len(strOUT(2))) & strOUT(2) _ & Space(12-Len(strOUT(2))) & strOUT(3) WScript.Echo strTXT End If Next '* '* Reinitialize '* Erase arrOUT intOUT = 0 Loop '* 'MsgBox "Done!",vbInformation,WScript.ScriptName
From: Tom Lavedas on 4 Jun 2008 09:26 On Jun 4, 7:23 am, simalt <sim...(a)gmail.com> wrote: > Could someone help me with this please. This puts out a list of > mailboxes from each server to a text file with tabs. Is it possible > to change this to comma delimited. Thanks. > > 'To list the largest mailbox on each server > > Option Explicit {snip} Try doing a mass substitution of ", " (including quotes) for every occurrence of vbTab in the script. Tom Lavedas =========== http://members.cox.net/tglbatch/wsh/
From: Richard Mueller [MVP] on 4 Jun 2008 09:39 In every statement you can replace each instance of vbTab with "," For example change this: If cDBG Then WScript.Echo ".LegacyDN = " _ & objExchange_Mailbox.LegacyDN _ & vbTab & ".MailboxDisplayName = " _ & objExchange_Mailbox.MailboxDisplayName _ & vbTab & ".Size = " _ & objExchange_Mailbox.Size _ & vbTab & ".TotalItems = " _ & objExchange_Mailbox.TotalItems To something like this: If cDBG Then WScript.Echo ".LegacyDN = " _ & objExchange_Mailbox.LegacyDN _ & "," & ".MailboxDisplayName = " _ & objExchange_Mailbox.MailboxDisplayName _ & "," & ".Size = " _ & objExchange_Mailbox.Size _ & "," & ".TotalItems = " _ & objExchange_Mailbox.TotalItems But in addition, if the aim is a comma delimied file you can read into a spreadsheet program, you probably don't want the values preceeded by strings like ".Size = ". Instead you may want to format just the values. For example the following makes more sense to me: If cDBG Then WScript.Echo objExchange_Mailbox.LegacyDN _ & "," & objExchange_Mailbox.MailboxDisplayName _ & "," & objExchange_Mailbox.Size _ & "," & objExchange_Mailbox.TotalItems -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "simalt" <simalt(a)gmail.com> wrote in message news:b9266239-f31f-4ca9-b0e3-821f654e8592(a)z66g2000hsc.googlegroups.com... > Could someone help me with this please. This puts out a list of > mailboxes from each server to a text file with tabs. Is it possible > to change this to comma delimited. Thanks. > > 'To list the largest mailbox on each server > > Option Explicit > '**** > '* Purpose: Display each Exchange_Mailbox found for Exchange server, > '* and show selected, formated properties on the > '* Exchange_Mailbox objects > '* Change: cComputerName [string] the computer to access (netbios > name) > '* Output: Displays the name of each Exchange_Mailbox and > properties > '* > '* based on > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3... > wmiref_cl_Exchange_Mailbox.asp > '* works only with Exchange 2003 servers > '**** '* > Const cServerNames = "c:\Scripts\serverNames.txt" > Const cWinMgmts = "winmgmts:{impersonationLevel=impersonate}!\ > \" > Const cWMINameSpace = "root/MicrosoftExchangeV2" > Const cWMIInstance = "Exchange_Mailbox" > Const cBOX = "OctelVMD,SMTP,System > Attendant,SystemMailbox" > Const cDBG = False '= Debug flag (Ture/False) > '* > Dim i, j, k > Dim arrBOX > arrBOX = Split(cBOX,",") > Dim booBOX > Dim intBOX > Dim strBOX > Dim intLEN > intLEN = 0 > Dim arrOUT() > Dim intOUT > intOUT = 0 > Dim strOUT > Dim strTMP > Dim strTXT > '* > Dim strWinMgmts ' Connection string for WMI > Dim objWMIExchange ' Exchange Namespace WMI object > Dim listExchange_Mailboxes ' Exchange_Mailbox collection > Dim objExchange_Mailbox ' A single Exchange_Mailbox WMI object > Dim cComputerName > Dim fileSys > Set fileSys = CreateObject("Scripting.FileSystemObject") > Dim fileToRead > Set fileToRead = fileSys.OpenTextFile(cServerNames,1) > '* > '* 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. > '* > '- Do While fileToRead.AtEndOfStream <> True > Do While Not fileToRead.AtEndOfStream > cComputerName = fileToRead.ReadLine > If cComputerName = "" Then Exit Do > WScript.Echo "Server name is: " & cComputerName > strWinMgmts = cWinMgmts & cComputerName & "\" & cWMINameSpace > '* > On Error Resume Next > Set objWMIExchange = GetObject(strWinMgmts) > '* > '* Verify connection to the WMI namespace on the server > '* > If Err.Number <> 0 Then > WScript.Echo "ERROR: Unable to connect to the WMI > namespace." > WScript.Echo Err.Description & " (" & Hex(Err.Number) & > ")" > WScript.Quit 1 > End If > On Error GoTo 0 > '* > '* The Resources that currently exist appear as a list of > '* Exchange_Mailbox instances in the Exchange namespace. > '* > Set listExchange_Mailboxes = > objWMIExchange.InstancesOf(cWMIInstance) > '* > '* Were any Exchange_Mailbox Instances returned? > '* > If listExchange_Mailboxes.count <= 0 Then > WScript.Echo "WARNING: No Exchange_Mailbox instances were > returned." > WScript.Quit 1 > End If > '* > WScript.Echo "Running mailbox size report for all stores on > server " & cComputerName & vbCrLf > > '* > '* Iterate through the list of Exchange_Mailbox objects. > '* > > If cDBG Then WScript.Echo "Loop!" > For Each objExchange_Mailbox in listExchange_Mailboxes > If cDBG Then WScript.Echo ".LegacyDN = " _ > & objExchange_Mailbox.LegacyDN _ > & vbTab & ".MailboxDisplayName = " > _ > & > objExchange_Mailbox.MailboxDisplayName _ > & vbTab & ".Size = " _ > & objExchange_Mailbox.Size _ > & vbTab & ".TotalItems = " _ > & objExchange_Mailbox.TotalItems > strTMP = objExchange_Mailbox.LegacyDN > strTMP = Mid(strTMP,InStrRev(strTMP,"CN=")+3) > strTMP = objExchange_Mailbox.MailboxDisplayName & " (" & > strTMP & ")" > If intLEN < Len(strTMP) Then intLEN = Len(strTMP) > ReDim Preserve arrOUT(intOUT) > arrOUT(intOUT) = (10^10-objExchange_Mailbox.Size) _ > & vbtab & strTMP _ > & vbtab & FormatNumber(objExchange_Mailbox.Size,0) _ > & vbtab & FormatNumber(objExchange_Mailbox.TotalItems, > 0) > If cDBG Then WScript.Echo intOUT & ". " & arrOUT(intOUT) > intOUT = intOUT + 1 > Next > Set objWMIExchange = Nothing > '* > '* Sort by objExchange_Mailbox.Size > '* > > If cDBG Then WScript.Echo "Sort!" > For i = UBound(arrOUT) - 1 To 0 Step -1 > For j = 0 To i > If arrOUT(j) > arrOUT(j+1) Then > k = arrOUT(j+1) > arrOUT(j+1) = arrOUT(j) > arrOUT(j) = k > End If > Next > Next > '* > '* List by objExchange_Mailbox.Size > '* > If cDBG Then WScript.Echo "List!" > strTXT = "Mailbox" & Space(intLEN-7) _ > & " Size" _ > & " Items" > WScript.Echo strTXT & vbCrLf & String(intLEN+12+10,"-") > For intOUT = 0 To UBound(arrOUT) > strOUT = Split(arrOUT(intOUT),vbTab) > '* > booBOX = True > For intBOX = 0 To UBound(arrBOX) > strBOX = arrBOX(intBOX) > If InStr(strOUT(1),strBOX) > 0 Then booBOX = False > Next > '* > If booBOX Then > strTXT = strOUT(1) & Space(intLEN-Len(strOUT(1))) _ > & Space(12-Len(strOUT(2))) & strOUT(2) _ > & Space(12-Len(strOUT(2))) & strOUT(3) > WScript.Echo strTXT > End If > Next > '* > '* Reinitialize > '* > Erase arrOUT > intOUT = 0 > Loop > '* > 'MsgBox "Done!",vbInformation,WScript.ScriptName > >
From: simalt on 4 Jun 2008 10:28 On Jun 4, 2:39 pm, "Richard Mueller [MVP]" <rlmueller- nos...(a)ameritech.nospam.net> wrote: > In every statement you can replace each instance of > > vbTab > > with > > "," > > For example change this: > > If cDBG Then WScript.Echo ".LegacyDN = " _ > & objExchange_Mailbox.LegacyDN _ > & vbTab & ".MailboxDisplayName = " _ > & objExchange_Mailbox.MailboxDisplayName _ > & vbTab & ".Size = " _ > & objExchange_Mailbox.Size _ > & vbTab & ".TotalItems = " _ > & objExchange_Mailbox.TotalItems > > To something like this: > > If cDBG Then WScript.Echo ".LegacyDN = " _ > & objExchange_Mailbox.LegacyDN _ > & "," & ".MailboxDisplayName = " _ > & objExchange_Mailbox.MailboxDisplayName _ > & "," & ".Size = " _ > & objExchange_Mailbox.Size _ > & "," & ".TotalItems = " _ > & objExchange_Mailbox.TotalItems > > But in addition, if the aim is a comma delimied file you can read into a > spreadsheet program, you probably don't want the values preceeded by strings > like ".Size = ". Instead you may want to format just the values. For example > the following makes more sense to me: > > If cDBG Then WScript.Echo objExchange_Mailbox.LegacyDN _ > & "," & objExchange_Mailbox.MailboxDisplayName _ > & "," & objExchange_Mailbox.Size _ > & "," & objExchange_Mailbox.TotalItems > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab -http://www.rlmueller.net > -- > > "simalt" <sim...(a)gmail.com> wrote in message > > news:b9266239-f31f-4ca9-b0e3-821f654e8592(a)z66g2000hsc.googlegroups.com... > > > > > Could someone help me with this please. This puts out a list of > > mailboxes from each server to a text file with tabs. Is it possible > > to change this to comma delimited. Thanks. > > > 'To list the largest mailbox on each server > > > Option Explicit > > '**** > > '* Purpose: Display each Exchange_Mailbox found for Exchange server, > > '* and show selected, formated properties on the > > '* Exchange_Mailbox objects > > '* Change: cComputerName [string] the computer to access (netbios > > name) > > '* Output: Displays the name of each Exchange_Mailbox and > > properties > > '* > > '* based on > >http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3.... > > wmiref_cl_Exchange_Mailbox.asp > > '* works only with Exchange 2003 servers > > '**** '* > > Const cServerNames = "c:\Scripts\serverNames.txt" > > Const cWinMgmts = "winmgmts:{impersonationLevel=impersonate}!\ > > \" > > Const cWMINameSpace = "root/MicrosoftExchangeV2" > > Const cWMIInstance = "Exchange_Mailbox" > > Const cBOX = "OctelVMD,SMTP,System > > Attendant,SystemMailbox" > > Const cDBG = False '= Debug flag (Ture/False) > > '* > > Dim i, j, k > > Dim arrBOX > > arrBOX = Split(cBOX,",") > > Dim booBOX > > Dim intBOX > > Dim strBOX > > Dim intLEN > > intLEN = 0 > > Dim arrOUT() > > Dim intOUT > > intOUT = 0 > > Dim strOUT > > Dim strTMP > > Dim strTXT > > '* > > Dim strWinMgmts ' Connection string for WMI > > Dim objWMIExchange ' Exchange Namespace WMI object > > Dim listExchange_Mailboxes ' Exchange_Mailbox collection > > Dim objExchange_Mailbox ' A single Exchange_Mailbox WMI object > > Dim cComputerName > > Dim fileSys > > Set fileSys = CreateObject("Scripting.FileSystemObject") > > Dim fileToRead > > Set fileToRead = fileSys.OpenTextFile(cServerNames,1) > > '* > > '* 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. > > '* > > '- Do While fileToRead.AtEndOfStream <> True > > Do While Not fileToRead.AtEndOfStream > > cComputerName = fileToRead.ReadLine > > If cComputerName = "" Then Exit Do > > WScript.Echo "Server name is: " & cComputerName > > strWinMgmts = cWinMgmts & cComputerName & "\" & cWMINameSpace > > '* > > On Error Resume Next > > Set objWMIExchange = GetObject(strWinMgmts) > > '* > > '* Verify connection to the WMI namespace on the server > > '* > > If Err.Number <> 0 Then > > WScript.Echo "ERROR: Unable to connect to the WMI > > namespace." > > WScript.Echo Err.Description & " (" & Hex(Err.Number) & > > ")" > > WScript.Quit 1 > > End If > > On Error GoTo 0 > > '* > > '* The Resources that currently exist appear as a list of > > '* Exchange_Mailbox instances in the Exchange namespace. > > '* > > Set listExchange_Mailboxes = > > objWMIExchange.InstancesOf(cWMIInstance) > > '* > > '* Were any Exchange_Mailbox Instances returned? > > '* > > If listExchange_Mailboxes.count <= 0 Then > > WScript.Echo "WARNING: No Exchange_Mailbox instances were > > returned." > > WScript.Quit 1 > > End If > > '* > > WScript.Echo "Running mailbox size report for all stores on > > server " & cComputerName & vbCrLf > > > '* > > '* Iterate through the list of Exchange_Mailbox objects. > > '* > > > If cDBG Then WScript.Echo "Loop!" > > For Each objExchange_Mailbox in listExchange_Mailboxes > > If cDBG Then WScript.Echo ".LegacyDN = " _ > > & objExchange_Mailbox.LegacyDN _ > > & vbTab & ".MailboxDisplayName = " > > _ > > & > > objExchange_Mailbox.MailboxDisplayName _ > > & vbTab & ".Size = " _ > > & objExchange_Mailbox.Size _ > > & vbTab & ".TotalItems = " _ > > & objExchange_Mailbox.TotalItems > > strTMP = objExchange_Mailbox.LegacyDN > > strTMP = Mid(strTMP,InStrRev(strTMP,"CN=")+3) > > strTMP = objExchange_Mailbox.MailboxDisplayName & " (" & > > strTMP & ")" > > If intLEN < Len(strTMP) Then intLEN = Len(strTMP) > > ReDim Preserve arrOUT(intOUT) > > arrOUT(intOUT) = (10^10-objExchange_Mailbox.Size) _ > > & vbtab & strTMP _ > > & vbtab & FormatNumber(objExchange_Mailbox.Size,0) _ > > & vbtab & FormatNumber(objExchange_Mailbox.TotalItems, > > 0) > > If cDBG Then WScript.Echo intOUT & ". " & arrOUT(intOUT) > > intOUT = intOUT + 1 > > Next > > Set objWMIExchange = Nothing > > '* > > '* Sort by objExchange_Mailbox.Size > > '* > > > If cDBG Then WScript.Echo "Sort!" > > For i = UBound(arrOUT) - 1 To 0 Step -1 > > For j = 0 To i > > If arrOUT(j) > arrOUT(j+1) Then > > k = arrOUT(j+1) > > arrOUT(j+1) = arrOUT(j) > > arrOUT(j) = k > > End If > > Next > > Next > > '* > > '* List by objExchange_Mailbox.Size > > '* > > If cDBG Then WScript.Echo "List!" > > strTXT = "Mailbox" & Space(intLEN-7) _ > > & " Size" _ > > & " Items" > > WScript.Echo strTXT & vbCrLf & String(intLEN+12+10,"-") > > For intOUT = 0 To UBound(arrOUT) > > strOUT = Split(arrOUT(intOUT),vbTab) > > '* > > booBOX = True > > For intBOX = 0 To UBound(arrBOX) > > strBOX = arrBOX(intBOX) > > If InStr(strOUT(1),strBOX) > 0 Then booBOX = False > > Next > > '* > > If booBOX Then > > strTXT = strOUT(1) & Space(intLEN-Len(strOUT(1))) _ > > & Space(12-Len(strOUT(2))) & strOUT(2) _ > > & Space(12-Len(strOUT(2))) & strOUT(3) > > WScript.Echo strTXT > > End If > > Next > > '* > > '* Reinitialize > > '* > > Erase arrOUT > > intOUT = 0 > > Loop > > '* > > 'MsgBox "Done!",vbInformation,WScript.ScriptName- Hide quoted text - > > - Show quoted text - Thanks. I tried it but still does not quite produce a comma ordered list.
|
Pages: 1 Prev: Script to remove list of users from groups... Next: Export AD users |