Avatar of Garry Shape
Garry Shape
Flag for United States of America asked on

Get names of users from Get-MailboxPermission

When I get a list of users or groups who have mailbox access to another user or group, how can I turn that list of users from domain\username into their display names?  

I'm trying this from the Exchange powershell after importing ActiveDirectory module:

Get-MailboxPermission -identity JSmith| select user | foreach ($user in $users) {Get-ADUser $user.Name}

Open in new window

But I get this in return:
Unexpected token 'in' in expression or statement.
+ Get-MailboxPermission -identity JSmith| select user | foreach ($user in <<<<  $users) {Get-ADUser $user}
    + CategoryInfo          : ParserError: (in:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Avatar of undefined
Last Comment

8/22/2022 - Mon
Rajitha Chimmani

You receive this error because you are trying to run foreach loop against non-existing variable $users. Try this line of commands

$Users = Get-MailboxPermission -identity JSmith
foreach($user in $users){
Get-ADUser $User.user | Select Name}

However, this command would not work for group entries as its get-ADGroup for groups.

Instead of using Get-ADuser and Get-ADgroup you could use Get-ADObject as common command for both user and groups. But i am not sure if Get-ADObject command will accept UPN as input identity
Rajitha Chimmani

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck