Solved

Exchange Powershell Get-User -Filter

Posted on 2010-11-09
2
1,413 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
2 Comments
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
Comment Utility
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
Comment Utility
Ken,

Thanks for that, works perfectly.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
In this video we show how to create a Distribution Group 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 Recipients >>…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now