Solved

Exchange Powershell Get-User -Filter

Posted on 2010-11-09
2
1,426 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In this video we show how to create an email address policy 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…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

827 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