Solved

Exchange | Powershell

Posted on 2014-12-20
6
130 Views
Last Modified: 2014-12-24
Hi,

i would like to read in the usernames from a CSV and to get only the information related to those users.  I have the below so far...

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,samaccountname,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}
0
Comment
Question by:cmatchett
[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
  • 2
  • 2
6 Comments
 
LVL 9

Expert Comment

by:dipersp
ID: 40511045
Not sure what your CSV looks like, but for example -

Name
John Smith
Bob Walker

Then -

Import-CSV C:\Users.csv | ForEach {Get-Mailbox $_.name -ResultSize Unlimited |Select-Object DisplayName,samaccountname,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}}
0
 
LVL 9

Accepted Solution

by:
dipersp earned 500 total points
ID: 40511046
Can also do this using aliases,  CSV would look like -

Alias
SmithJ
WalkerB

Then -

Import-CSV C:\Users.csv | ForEach {Get-Mailbox $_.alias -ResultSize Unlimited |Select-Object DisplayName,samaccountname,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}}
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40511597
To avoid that mass of curly braces, I would rewrite that.
Import-CSV -header Identity c:\Users.csv |
  Get-Mailbox |
  select DisplayName, SamAccountName, ServerName, PrimarySmtpAddress,
    @{n="EmailAddresses"; e={$_.EmailAdresses | ? { $_.PerfixString -.ceq "smtp" } | select -Expand SmtpAddress}}

Open in new window

If you have only the names in the CSV, it is no CSV, btw - just a simple text file. and you can use Just Get-Content.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cmatchett
ID: 40516491
Qlemo, that doesn't work for me
0
 

Author Closing Comment

by:cmatchett
ID: 40516493
excellent
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40517203
The is a typo in my code - PerfixString instead of PrefixString,  maybe that's why it didn't work.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
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…

705 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