header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Exchange mailbox sizes to Excel
Last Post 09 Feb 2012 02:18 AM by BostjanK-SI. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
NatrixzUser is Offline
New Member
New Member
Posts:3
Avatar

--
25 Jan 2012 05:11 AM
    Oke, so this script used to work on Powershell V1...but since Powershell V2 this doesn't work anymore.

    Can anyone tell what I am doing wrong with it?

    Code below:
    --------------------------------------

    ############### script to get all mailbox databases and list users and size of each mailbox and items count.
    #list servers in c:\server.csv ie server1,server2,server3

    $Excel = New-Object -Com Excel.Application
    $Excel.DisplayAlerts = $False
    $Excel.visible = $True
    $Excel = $Excel.Workbooks.Add(1)
    $Sheet = $Excel.WorkSheets.Item(1)
    $Sheet.Cells.Item(1,1) = "Database Name"
    $Sheet.Cells.Item(1,2) = "Name"
    $Sheet.Cells.Item(1,3) = "Mailbox Size"
    $Sheet.Cells.Item(1,4) = "Item Count"


    $WorkBook = $Sheet.UsedRange

    $intRow = 2
    $MBdatabase = import-csv c:\server.csv
    foreach($row in $MBdatabase)
    {
    $colitems = get-mailboxserver -Identity $MBdatabase| get-mailboxstatistics |where {$_.TotalItemSize -gt 0mb} |sort-object ItemCount -Descending | Select-object Displayname,`
    @{>

    foreach ($obj in $colitems)

    {



    if($error.count -gt 0){
    Write-host "Database not present"
    $Sheet.Cells.Item($intRow,1) = $obj.Name
    $Sheet.Cells.Item($intRow,2) = Write-Output "Server not avail"
    $error.clear()
    $intRow = $intRow + 1
    }
    else
    {


    $Sheet.Cells.Item($intRow,1) = $obj.servername +"\"+ $obj.storagegroupname +"\"+ $obj.Databasename
    $Sheet.Cells.Item($intRow,2) = $obj.displayname
    $Sheet.Cells.Item($intRow,3) = $obj.MBSize
    $Sheet.Cells.Item($intRow,4) = $obj.ItemCount


    $intRow = $intRow + 1
    $WorkBook.EntireColumn.AutoFit()


    } }}

    mailboxtoexcel.ps1

    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    25 Jan 2012 07:01 AM
    Can you provide the error?

    Is this a typo in your above code?
    ...
    @{>
    ...


    NatrixzUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    25 Jan 2012 07:04 AM
    Ofcourse!

    This is the error, copied from PS.

    The hash literal was incomplete.
    At C:\Users\Nick\Documents\Powershell Scripts\Untested\mailboxtoexcel.ps1:22 ch
    ar:3
    + @{ <<<< >
    + CategoryInfo : ParserError: (CloseBraceToken:TokenId) [], Parse
    Exception
    + FullyQualifiedErrorId : IncompleteHashLiteral

    But it actually worked before with the @{>
    Now whatever I do or change it just won't parse it anymore.


    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    25 Jan 2012 07:14 AM
    Sorry, I don't have time to troubleshoot, but that is an invalid syntax for sure, and should not have working in v1.


    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    25 Jan 2012 07:16 AM
    The script you posted would have never worked.
    Your Select-Object on line 21 is incomplete, and line 22 is not valid PowerShell.

    I'd try this:
    ############### script to get all mailbox databases and list users and size of each mailbox and items count.
    #list servers in c:\server.csv ie server1,server2,server3
    
    $Excel = New-Object -Com Excel.Application
    $Excel.DisplayAlerts = $False
    $Excel.visible = $True
    $Excel = $Excel.Workbooks.Add(1)
    $Sheet = $Excel.WorkSheets.Item(1)
    $Sheet.Cells.Item(1,1) = "Database Name"
    $Sheet.Cells.Item(1,2) = "Name"
    $Sheet.Cells.Item(1,3) = "Mailbox Size"
    $Sheet.Cells.Item(1,4) = "Item Count"
    
    
    $WorkBook = $Sheet.UsedRange
    
    $intRow = 2
    $MBdatabase = import-csv c:\server.csv
    foreach($row in $MBdatabase)
    {
    $colitems = get-mailboxserver -Identity $MBdatabase| get-mailboxstatistics |where {$_.TotalItemSize -gt 0mb}
        foreach ($obj in $colitems)
        {
            if($error.count -gt 0){
                Write-host "Database not present"
                $Sheet.Cells.Item($intRow,1) = $obj.Name
                $Sheet.Cells.Item($intRow,2) = Write-Output "Server not avail"
                $error.clear()
                $intRow = $intRow + 1
            }
            else
            {
            $Sheet.Cells.Item($intRow,1) = $obj.servername +"\"+ $obj.storagegroupname +"\"+ $obj.Databasename
            $Sheet.Cells.Item($intRow,2) = $obj.displayname
            $Sheet.Cells.Item($intRow,3) = $obj.MBSize
            $Sheet.Cells.Item($intRow,4) = $obj.ItemCount
            $intRow = $intRow + 1
            $WorkBook.EntireColumn.AutoFit()
            } 
        }
    }  


    Note that it is untested.
    Karl


    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    NatrixzUser is Offline
    New Member
    New Member
    Posts:3
    Avatar

    --
    25 Jan 2012 10:39 PM
    Well, thing is i've recently come into a new company and i've just moved all their scripts into my temp folder for testing what still works and what doesn't, and what it does.
    (Actually more checking if it's harmfull first and then try if it works)

    So anything tested go's into that, untested or not working is in untested.
    Would suck if it didn't work cause then i'd need to make/find a new script that does work. (since they say it worked)


    BostjanK-SIUser is Offline
    New Member
    New Member
    Posts:11
    Avatar

    --
    09 Feb 2012 02:18 AM
    wouldn't it be easier to just write something like that

    Get-MailboxDatabase | Get-MailboxStatistics | select @{name="Database Name";expression={$_.databasename}}, @{name="Name";expression={$_.displayname}}, {name="Size";expression={$_.TotalItemSize.value.toMB()}}, @{name="Item Count";expression={$_.itemcount}} | export-csv mailboxusage.csv -delimiter ";" -noclobber -notypeinformation -encoding UTF8

    encoding is just for non english characters

    This report can be open with excel without any data conversion.


    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer