Solved

need assistance with a powershell script to export out mailbox statistics for a number of users

Posted on 2013-02-07
11
501 Views
Last Modified: 2013-02-07
Can someone provide a way for me to run this script but add the "import-csv" option so that i can run it against multiple accounts? [100+]

here is the script that works perfectly for a single mailbox to export out folder statistics:
Get-MailboxFolderStatistics -id Joe_Smith | Select Identity,FolderSize,ItemsInFolder,NewestItemReceiveDate |Export-CSV c:\results.csv

thanks in advance!

Quest AD Cmdlet version would be fine as well

S.
0
Comment
Question by:siber1
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 28

Expert Comment

by:becraig
ID: 38865161
$accts = import-csv c:\accts.csv

$accts| foreach-object {do something}
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38865163
If you have the user list in text file then try..
GC c:\User.txt | %{
Get-MailboxFolderStatistics -id $_ | Select Identity,FolderSize,ItemsInFolder,NewestItemReceiveDate} | Export-Csv c:\report.csv -NoTypeInformation

Open in new window


input file format..
UserA
UserB
UserC

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38865165
Assume u have user in each line u can run the following:

gc users.csv | %{
Get-MailboxFolderStatistics -id $_ | Select Identity,FolderSize,ItemsInFolder,NewestItemReceiveDate |Export-CSV c:\results.csv
}
0
 
LVL 28

Expert Comment

by:becraig
ID: 38865172
$accts = import-csv c:\accts.csv

$accts| foreach-object {do something
#for specific values
Get-MailboxFolderStatistics -id $_.id | Select Identity,FolderSize,ItemsInFolder,NewestItemReceiveDate |Export-CSV c:\results.csv


}
0
 
LVL 28

Expert Comment

by:becraig
ID: 38865181
$accts = import-csv c:\accts.csv
$outpath = c:\results.csv
$accts| foreach-object {do something
#for specific values
$mbinfo += Get-MailboxFolderStatistics -id $_.id | Select Identity,FolderSize,ItemsInFolder,NewestItemReceiveDate
}
$mbinfo | Select * | Export-Csv $outpath -NoTypeInformation
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38865183
Export-Csv inside the foreach loop will cause the result file get overwritten for each user.. it should be placed outside the loop..
0
 
LVL 5

Expert Comment

by:coraxal
ID: 38865197
One approach would be to use custom objects to collect the information from each mailbox for later export. In this example, you'd have your list of users in a text file with a valid parameter (i.e. SamAccountName, DN, alias, etc.)
$folderStatsOutput = @()
Import-Csv c:\temp\users.txt | ForEach-Object {
   $folderStatsObj = Get-MailboxFolderStatistics -id $_
   $objTemp = New-Object PSObject -Property {
         Identity = $folderStatsObj.Identity
         FolderSize = "{0:0,0}"$folderStatsObj.FolderSize.ToKB()
         ItemsInFolder = $folderStatsObj.ItemsInFolder
         NewestItemReceiveDate = $folderStatsObj.NewestItemReceiveDate
    }
    $folderStatsOutput += $objTemp
}

$folderStatsOutput | 
Select-Object Identity,FolderSize,ItemsInFolder,NewestItemReceivedDate |
Export-Csv C:\temp\folderstats_results.csv -NoType

Open in new window

0
 
LVL 5

Expert Comment

by:coraxal
ID: 38865207
Sorry..
# change this line
Import-Csv c:\temp\users.txt | ForEach-Object {

# to this

Get-Content c:\temp\users.txt | ForEach-Object {

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38865220
$results = @()
gc users.csv | %{
$results += , @(Get-MailboxFolderStatistics -id $_ | Select Identity,FolderSize,ItemsInFolder,NewestItemReceiveDate)
}

$results | export-csv c:\results.csv
0
 

Expert Comment

by:RTedrow
ID: 38865250
I can't test this at the moment but this was quick and dirty.  If the hash array does not work let me know and I'll rework it when I get to my desk:

$list=@()
foreach($user in cat c:\scripts\userlist.txt)
{
      $mbstat = Get-MailboxFolderStatistics -id $user Select

      $hash=@{
            Identity = $mbstat Identity
            Folder_Size = $mbstat FolderSize
            Items = $mbstat ItemsInFolder
            Newest_Item = $mbstat.NewestItemReceiveDate
            }

            $obj = New-Object PSObject -Property $hash

            $list += $obj
}

$list | export-csv C:\Scripts\MBInfo.csv
0
 

Author Closing Comment

by:siber1
ID: 38865314
thanks all for the responses. Subsun you were first and this works perfectly. much appreciated.

S.
0

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
A procedure for exporting installed hotfix details of remote computers using powershell
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now