Link to home
Start Free TrialLog in
Avatar of cmatchett
cmatchettFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Exchange | Powershell


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}}}
Avatar of dipersp
Flag of United States of America image

Not sure what your CSV looks like, but for example -

John Smith
Bob Walker

Then -

Import-CSV C:\Users.csv | ForEach {Get-Mailbox $ -ResultSize Unlimited |Select-Object DisplayName,samaccountname,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}}
Avatar of dipersp
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Qlemo
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.
Avatar of cmatchett


Qlemo, that doesn't work for me
The is a typo in my code - PerfixString instead of PrefixString,  maybe that's why it didn't work.