exchange powershell 2007 question

I have a command that I run to get email statistics for a mailbox. What I have been trying to accomplish is two things. The first is being able to do this with multiple recipients and to also get a sum total at the end of each folder structure. For example

get-mailboxfolderstatistics -identity "alias" | select Name, Foldersize, Itemsinfolder

This produces for the following output as aa hypothetical

Name                       FolderSize                             ItemsInFolder
----                       ----------                             -------------
Top of Information Store   0B                                                 0
Calendar                   4098B                                              2
Contacts                   0B                                                 0
Deleted Items              0B                                                 0
Drafts                     138B                                               1
Inbox                      774B                                               3
Journal                    0B                                                 0
Junk E-Mail                0B                                                 0
Notes                      0B                                                 0
Outbox                     0B                                                 0
Sent Items                 562B                                               2
Tasks                      0B                                                 0
Top of Information Store   0B                                                 0
Calendar                   0B                                                 0
Contacts                   0B                                                 0
Deleted Items              0B                                                 0
Drafts                     0B                                                 0
Inbox                      0B                                                 0
Journal                    0B                                                 0
Notes                      0B                                                 0
Outbox                     0B                                                 0
Sent Items                 0B                                                 0
Tasks                      0B                                                 0
Top of Information Store   0B                                                 0
Calendar                   0B                                                 0
Contacts                   0B                                                 0
Deleted Items              0B                                                 0
Drafts                     0B                                                 0
Inbox                      0B                                                 0
Journal                    0B                                                 0
Notes                      0B                                                 0
Outbox                     0B                                                 0
Sent Items                 0B                                                 0
Tasks                      0B                                                 0


I would like to get this to list for multple users. I have tried the following where the list.txt file contains the list of users.

get-content c:\temp\list.txt | foreach-object { get-mailboxfolderstatistics $_ } | select Name, Foldersize, Itemsinfolder

I only receive the output for one of the users and not all of them. I would like them to be listed with 3 or more lines free and then the next user. Also, if possible I would like to see if we can add each column together as well after each user, thanks
techdriveAsked:
Who is Participating?
 
prashanthdConnect With a Mentor Commented:
Ignore earlier code, missed something
"User,FolderName,FolderSize,ItemsinFolder"|out-file output.txt
get-content list.txt | foreach-object { 

write-host $_
$_ | out-file c:\output.txt -append

$query1=get-mailboxfolderstatistics $_  | select Name, Foldersize, Itemsinfolder 

foreach ($q1 in $query1){
",$($q1.name),$($q1.Foldersize),$($q1.Itemsinfolder)"| out-file c:\output.txt -append }

$query2=get-mailboxstatistics $_  | select TotalItemSize, Itemcount 
",Total,$($query2.TotalItemSize),$($query2.Itemcount)"| out-file c:\output.txt -append
}

Open in new window

0
 
RadweldCommented:
Get-mailbox | get-mailboxstatistics | select name, foldersize, itemsinfolder

This will return the mailbox stats for all mail users

If you add | export-Csv c:\mailstats.Csv then you can export this data to a Csv for further examination.
0
 
prashanthdCommented:
Try the following, it will create an output in csv format
"User,FolderName,FolderSize,ItemsinFolder"|out-file output.txt
get-content list.txt | foreach-object { 

write-host $_
$_ | out-file output.txt -append

$query1=get-mailboxfolderstatistics $_  | select Name, Foldersize, Itemsinfolder 

foreach ($q1 in $query1){
",$($q1.name),$($q1.Foldersize),$($q1.Itemsinfolder)"| out-file output.txt -append }

$query2=get-mailboxstatistics $_  | select TotalItemSize, Itemcount 
",Total,$($query2.TotalItemSize),$($query2.Itemcount)"| out-file output.txt -append
}

Open in new window

0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
techdriveAuthor Commented:
Neither solution worked
0
 
prashanthdCommented:
Did it create output file?
0
 
RadweldCommented:
There's a typo in my original post, probably because I'm on a phone, get-mailbox | get-mailboxfolderstatistics is the correct command
0
 
techdriveAuthor Commented:
prashanthd: I ran your script above and all this listed was the 3 users I tested this on. I placed 3 user aliases in the list.txt file. When I ran the script it only listed the users


ex:


./mailsizes.ps1
testuser1
testuser2
testuser3

No other output. I saved the contents of your script into a .ps1 file on a windows r2 2008 server.
0
 
techdriveAuthor Commented:
RadWeld your post is incorrect because I am not wanting EVERY user in the exchange environment. I am only wanting a select portion in which I have defined in my text file.
0
 
RadweldCommented:
Ok then change your txt file into a Csv, Ensure the header is name or some other similar descriptor, you would then

Import-Csv <location\file.Csv> | foreach-object -process {get-mailboxfolderstatistics -identity $_.name | ft name, itemsinfolder, foldersize}

The key here is -process this might work on your original command but definately works with csvs

Should do it
0
 
techdriveAuthor Commented:
I see what you are trying to do. I am going to see if I can play with this a little bit myself. I am getting the following error when running the command.

boxfolderstatistics -identity $_.name | ft name, itemsinfolder, foldersize}
Get-MailboxFolderStatistics : Cannot bind argument to parameter 'Identity' beca
use it is null.
At line:1 char:94
+ get-content c:\temp\list.csv | foreach-object -process {get-mailboxfolderstat
istics -identity  <<<< $_.name | ft name, itemsinfolder, foldersize}
Get-MailboxFolderStatistics : Cannot bind argument to parameter 'Identity' beca
use it is null.
At line:1 char:94
0
 
prashanthdCommented:
Try the following, it will create an output file c:\output.txt
"User,FolderName,FolderSize,ItemsinFolder"|out-file output.txt
get-content list.txt | foreach-object { 

write-host $_
$_ | out-file c:\output.txt -append

$query1=get-mailboxfolderstatistics $_  | select Name, Foldersize, Itemsinfolder 

foreach ($q1 in $query1){
",$($q1.name),$($q1.Foldersize),$($q1.Itemsinfolder)"| out-file output.txt -append }

$query2=get-mailboxstatistics $_  | select TotalItemSize, Itemcount 
",Total,$($query2.TotalItemSize),$($query2.Itemcount)"| out-file c:\output.txt -append
}

Open in new window

0
 
techdriveAuthor Commented:
Prash the data is going into the output file. Looks fine here.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.