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
Solved

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

Posted on 2013-02-07
11
505 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
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…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

838 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