Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Exchange Powershell Get-User -Filter

Posted on 2010-11-09
2
Medium Priority
?
1,452 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 2000 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
To show how to generate a certificate request 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 Servers >> Certificates…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

721 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