?
Solved

Exchange | Powershell

Posted on 2014-12-20
6
Medium Priority
?
136 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 2000 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In this video we show how to create a Contact 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 >> Contact ta…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
Suggested Courses

777 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