header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Get-Mailboxstatistics, output not complete results
Last Post 17 Aug 2011 11:45 AM by Karl Mitschke. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Adrian RyanUser is Offline
New Member
New Member
Posts:3
Avatar

--
16 Aug 2011 06:44 PM
    Hi,

    I have a recurring issue with try to get-mailboxstatistics for a list of mailboxes (using get-content) by using the foreach loop and getting correct results outputted to a csv file.

    My coding runs something like this:


    $file= Get-content C:\scripts\infiles\mylist.txt
    $outfile= c:\scripts\outfiles\mbx_stats_results.csv

    Foreach($mbx in $file){
    Get-Mailboxstatistics $mbx | SELECT DisplayName, TotalItemSize | Export-Csv $outfile
    }

    The problem is that only the last mbx in $file is outputted. However, if I take away the Export-csv, the results display correctly in the shell.

    What exactly is the magic mix of coding when I want results for a command using a subset of data from a list, and outputting those results to a csv file?

    I have the same issue when trying to get mailbox permissions from a list of mailboxes.


    Any help would be greatly appreciated.
    Powershell Rocks! So do I, back and forth....when i don't understand the commands! :-)


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

    --
    17 Aug 2011 06:35 AM
    Adrian;
    As you have discovered, Export-Csv does not append data, it overwrites.
    See if Dmitry Sotnikov’s post helps:
    http://dmitrysotnikov.wordpress.com...sv-append/

    Also, you can do thei in your foreach:
    
    Foreach($mbx in Get-content C:\scripts\infiles\mylist.txt)
    


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

    --
    17 Aug 2011 11:12 AM
    Thankyou for the reply and pointer to Dmitry's blog. 


    I also found that If I saved the command into a ps1 then piped the export, the csv file automatically gave me all the results (appended the data) eg:

    getmailboxstats.ps1 | Export-Csv c:\scripts\outfiles\MbxStatsResults.csv

    Helps to have a go eh?

    Thanks once again :-)
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    17 Aug 2011 11:45 AM
    You can also do this:
    
    $outfile= c:\scripts\outfiles\mbx_stats_results.csv
    $Data = @()
    Foreach($mbx in Get-content C:\scripts\infiles\mylist.txt){
    $Data += Get-Mailboxstatistics $mbx | SELECT DisplayName, TotalItemSize
    }
    $Data | Export-Csv $outfile -NoTypeInformation 
    

    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    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