Solved

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

Posted on 2013-02-07
11
503 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 29

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 29

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 29

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
In this video we show how to create an Address List 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 Organization >> Ad…
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…

896 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

14 Experts available now in Live!

Get 1:1 Help Now