Solved

Exchange | Powershell

Posted on 2014-12-20
6
123 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
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.
In this video we show how to create a User Mailbox 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 >> Mailb…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

822 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