cmatchett
asked on
Exchange | Powershell
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 ,ServerNam e,PrimaryS mtpAddress , @{Name=“EmailAddresses”;Ex pression={ $_.EmailAd dresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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}}
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.
ASKER
Qlemo, that doesn't work for me
ASKER
excellent
The is a typo in my code - PerfixString instead of PrefixString, maybe that's why it didn't work.
Name
John Smith
Bob Walker
Then -
Import-CSV C:\Users.csv | ForEach {Get-Mailbox $_.name -ResultSize Unlimited |Select-Object DisplayName,samaccountname