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

PowershellExchange

Avatar of undefined
Last Comment
SCC-EE

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
KenMcF

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SCC-EE

ASKER
Ken,

Thanks for that, works perfectly.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23