Link to home
Start Free TrialLog in
Avatar of Tony Giangreco
Tony GiangrecoFlag for United States of America

asked on

Exchange 2007 Report from PowerShell Script problem

I have this script running on my Windows 2008 r2 Exchange 2007 server.

$exclude = GC C:\PS-Scripts\exclude.txt
$mailboxes  = Get-Mailbox -ResultSize Unlimited | ?{$exclude -notcontains $_.samaccountname}

$exclude = GC C:\PS-Scripts\exclude.txt
$mailboxes  = Get-Mailbox -ResultSize Unlimited | ?{$exclude -notcontains $_.samaccountname}
$report = @()
foreach ($mailbox in $mailboxes)
{
    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope Inbox | Where {$_.FolderPath -eq "/Inbox"}

    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name "Display Name" -Value $mailbox.DisplayName
    $mbObj | Add-Member -MemberType NoteProperty -Name "Inbox Size (Mb)" -Value $inboxstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name "Inbox Items" -Value $inboxstats.ItemsinFolder
    $report += $mbObj
}

I'm having these problems:
1. When i paste the script in powershell, do a select All, Copy & Paste into notepad, the report width is very wide and it wraps.
2. I need to capture the output in both CSV and as a regular text file that open in notepad.
3. The exclude option doesn't work. I have two text files I've tried (one with employees) and (One with email addresses) in the following format and nothing works.

joe@me.com
Pete@me,com
You@me.com

Joe Peterson
Mary Peterson
Al Peterson

Your suggestions are appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Amit Kumar
Amit Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tony Giangreco

ASKER

I'll try it later when I get to the office.

Is there anyway to add  (count & folder size) Sent Items and Deleted Items to the report?
Any ideas on the exclude problem?
same way you did it for Inbox folder
Oh I fogot it... let me check it again
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, I'll try it later today. Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
CSV file won't overwrite but yes txt file will but i also mentioned append after editing my comment in last... E-mail address also can be used to exclude users still whatever works. I wish either ur or mine whichever script work for user I am happy.. at least i got to learn smthing thanks anyways.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Amit, the CSV file will also get overwritten each time. Your last change makes the text file worse, as it appends the cummulated output (because of the -append). Both exports should just be moved out of the loop. And this does not make much sense:
 $report = $report += $mbObj
you assign the the result of append data to $result to $result ;-). It should just be
 $report += $mbObj
May be but i made couple of scripts in my env and i got expected results.. Still i will try your suggestion tooo...
Thanks for the help