Link to home
Start Free TrialLog in
Avatar of Garry Shape
Garry ShapeFlag 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 Rajitha Chimmani
Rajitha Chimmani
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Rajitha Chimmani
Rajitha Chimmani
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial