Solved

Exchange | Powershell

Posted on 2014-12-20
6
126 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
  • 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 69

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 69

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

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

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.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
This video discusses moving either the default database or any database to a new volume.

749 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