?
Solved

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

Posted on 2013-02-07
11
Medium Priority
?
510 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Four New Appliances. Same Industry-leading Speeds.

But don't take it from us.  The Firebox M370 is Miercom tested and Miercom approved, outperforming its competitors for stateless and stateful traffic throughput scenarios.  Learn more about the M370, M470, M570 and M670 and find the right solution for your organization today!

 
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
 
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

Four New Appliances. Same Industry-leading Speeds.

But don't take it from us.  The Firebox M370 is Miercom tested and Miercom approved, outperforming its competitors for stateless and stateful traffic throughput scenarios.  Learn more about the M370, M470, M570 and M670 and find the right solution for your organization today!

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
New style of hardware planning for Microsoft Exchange server.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 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