Solved

Exchange Powershell Get-User -Filter

Posted on 2010-11-09
2
1,430 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:SCC-EE
[X]
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
2 Comments
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 34092371
Take a look at the attached script and test it out. let me know if you stil have any problems.
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin  
$Date = Get-date -f 'ddMMyy'  
$out = @()
$out += "Name,Office,Company,DataBase,TotalItemSize"
 $user = get-user -Filter { LastName -eq 'Smith' -and RecipientType -eq "UserMailbox"} 
 foreach ($u in $user) {
 $stats = get-mailboxstatistics $u.UserPrincipalName
 $out += "$([char]34)$($u.name)$([char]34),$($u.office),$($u.company),$($stats.DataBase),$($stats.TotalItemSize.Value.tomb())"
 }
 $out | out-file c:\Mailbox-Report-$date.csv

Open in new window

0
 

Author Comment

by:SCC-EE
ID: 34129459
Ken,

Thanks for that, works perfectly.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
how to add IIS SMTP to handle application/Scanner relays into office 365.

733 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