Link to home
Start Free TrialLog in
Avatar of SCC-EE
SCC-EE

asked on

Exchange Powershell Get-User -Filter

Guys,

Having a little bit of a drama geting this to work exactly the way I want. I need to filter the output of a query being run against an Exchange Server, to only come back with stats for users with a surname of "smith" for example. I plan to actually run this against other attributes later, but for the sake of this article, lets use the sn (or as EMS has it "LastName").

Attached is the code I'm working with.
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin

$TotalItemSize = @{n="TotalItemSize(MB)";e={ $stats.TotalItemSize.Value.ToMB() }}
$Database = @{n="Database";e={ $stats.database }} 
$Company = @{n="Company";e={ $user.Company }}
$Date = Get-date -f 'ddMMyy'

get-mailbox -server "EXC01" | foreach {
 $stats = get-mailboxstatistics $_
 $user = get-user -Filter { LastName -eq 'Smith' } 
 $_ | select Name,Office,$Database,$TotalItemSize,$Company
} | Sort-Object Company,Office,Name | export-csv C:\Mailbox-Report-$date.csv

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of KenMcF
KenMcF
Flag of United States of America 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 SCC-EE
SCC-EE

ASKER

Ken,

Thanks for that, works perfectly.