![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | help with formatting 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/de...ary/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 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: help with formatting 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@xxxxxx> wrote in message news:b9266239-f31f-4ca9-b0e3-821f654e8592@xxxxxx Quote: > 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/de...ary/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 > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: help with formatting On Jun 4, 2:39*pm, "Richard Mueller [MVP]" <rlmueller- nos...@xxxxxx> wrote: Quote: > 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...@xxxxxx> wrote in message > > news:b9266239-f31f-4ca9-b0e3-821f654e8592@xxxxxx > > > Quote: > > 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. Quote: > > 'To list the largest mailbox on each server Quote: > > *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/de...ary/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 Quote: > > * * * '* > > * * * '* Iterate through the list of Exchange_Mailbox objects. > > * * * '* Quote: > > * * * *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 > > * * * '* Quote: > > * * * *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 - list. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Need Formatting Help!!!! | General Discussion | |||
| Formatting HD | General Discussion | |||
| formatting | Vista General | |||
| Formatting | Vista installation & setup | |||
| Re: Formatting Bug | PowerShell | |||