Solved

Powershell to get shared mailboxes permissions

Posted on 2016-09-07
25
101 Views
Last Modified: 2016-09-20
Looking for the following in powershell...

List of all shared mailboxes with the following detail

1. Name
2. Email address
3. Owner
4. Last logon date
5. Last Logon user
6. List of users who have full access
7. List of users who have sendas
8. If possible, last accesa date

I have a working script but unable to get all the information in one go.
0
Comment
Question by:ARM2009
  • 12
  • 12
25 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 41789889
Which version of exchange..

How you going to identify the shared mailbox? is there any naming standard you use or is it created in a specific OU?
0
 

Author Comment

by:ARM2009
ID: 41790065
No specific OU ... Exch 2010

Search for all shared mailboxes
0
 
LVL 14

Expert Comment

by:Todd Nelson
ID: 41790630
Getting a list of shared mailboxes is the easy part...

Get-Mailbox -ResultSize Unlimited | Where-Object { $_.RecipientTypeDetails -eq "SharedMailbox" } | fl Name,PrimarySmtpAddress

Open in new window


And getting who has full permissions is simple enough...

Get-Mailbox -ResultSize Unlimited | Where-Object {$_.RecipientTypeDetails -eq "SharedMailbox"} | Get-MailboxPermission | Where-Object { $_.AccessRights -eq "FullAccess" }

Open in new window


For me, the rest is a challenge that I can't test at the moment.

Let us know what you come up with.

P.S.  Shared mailboxes don't have an owner.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 40

Expert Comment

by:Subsun
ID: 41791039
3. Owner
It depends how your organization is managing the owner details, some add the owner as manager, some add it in exchange custom attributes

For rest of the details you can use following code..
$RMailbox = Get-Mailbox -RecipientTypeDetails Sharedmailbox -ResultSize Unlimited
$(Foreach ($R in $RMailbox){
$St = $R | Get-MailboxStatistics 
	New-Object PSObject -Property @{
		Name = $R.Name
		Email = $R.PrimarySmtpAddress
		LastLoggedOnUserAccount = $St.LastLoggedOnUserAccount
		LastLogonTime  = $St.LastLogonTime
		LastLogoffTime = $St.LastLogoffTime
		FullMBXPerm = ($R | Get-MailboxPermission |?{$_.AccessRights -like "Fullaccess" -and $_.User -NotMatch "(Self|SYSTEM|^S-1-5-)"} | %{$_.User.ToString()}) -join ","
		SendAs = ($R | Get-ADPermission |?{$_.ExtendedRights -like "Send-as" -and $_.User -NotMatch "(Self|SYSTEM|^S-1-5-)"} | %{$_.User.ToString()}) -join ","
	}
}) | Select Name,Email,FullMBXPerm,SendAS,Last*

Open in new window

1
 

Author Comment

by:ARM2009
ID: 41796155
Owner information is being pulled from the "Manager" info in AD.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41796868
I have added manager field..
$RMailbox = Get-Mailbox -RecipientTypeDetails Sharedmailbox -ResultSize Unlimited
$(Foreach ($R in $RMailbox){
$St = $R | Get-MailboxStatistics 
	New-Object PSObject -Property @{
		Name = $R.Name
		Email = $R.PrimarySmtpAddress
		LastLoggedOnUserAccount = $St.LastLoggedOnUserAccount
		LastLogonTime  = $St.LastLogonTime
		LastLogoffTime = $St.LastLogoffTime
		FullMBXPerm = ($R | Get-MailboxPermission |?{$_.AccessRights -like "Fullaccess" -and $_.User -NotMatch "(Self|SYSTEM|^S-1-5-)"} | %{$_.User.ToString()}) -join ","
		SendAs = ($R | Get-ADPermission |?{$_.ExtendedRights -like "Send-as" -and $_.User -NotMatch "(Self|SYSTEM|^S-1-5-)"} | %{$_.User.ToString()}) -join ","
		Owner = ($R | get-recipient).Manager.Name
	}
}) | Select Name,Email,Owner,FullMBXPerm,SendAS,Last*

Open in new window

0
 

Author Comment

by:ARM2009
ID: 41798276
the manager info is not pulled via this script... its all blank. i have checked that that field has information. i can pull that via Quest powershell ...

any ideas what attributes it uses to store that info?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41798288
Can you run following command and post output?
Get-Recipient UserA | Select -exp Manager

Open in new window

0
 

Author Comment

by:ARM2009
ID: 41798308
this gives the manager info on that particular account.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41798312
What about?
(Get-Recipient UserA).Manager.Name

Open in new window

0
 

Author Comment

by:ARM2009
ID: 41798315
blank.... if i use (Get-Recipient UserA).Manager.Name
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41798325
If this work (Get-Recipient UserA).Manager

The use..
$RMailbox = Get-Mailbox -RecipientTypeDetails Sharedmailbox -ResultSize Unlimited
$(Foreach ($R in $RMailbox){
$St = $R | Get-MailboxStatistics 
	New-Object PSObject -Property @{
		Name = $R.Name
		Email = $R.PrimarySmtpAddress
		LastLoggedOnUserAccount = $St.LastLoggedOnUserAccount
		LastLogonTime  = $St.LastLogonTime
		LastLogoffTime = $St.LastLogoffTime
		FullMBXPerm = ($R | Get-MailboxPermission |?{$_.AccessRights -like "Fullaccess" -and $_.User -NotMatch "(Self|SYSTEM|^S-1-5-)"} | %{$_.User.ToString()}) -join ","
		SendAs = ($R | Get-ADPermission |?{$_.ExtendedRights -like "Send-as" -and $_.User -NotMatch "(Self|SYSTEM|^S-1-5-)"} | %{$_.User.ToString()}) -join ","
		Owner = ($R | get-recipient).Manager
	}
}) | Select Name,Email,Owner,FullMBXPerm,SendAS,Last*

Open in new window

0
 

Author Comment

by:ARM2009
ID: 41798996
that provided the information....  thanks

owner info comes as  - domain.com/People/HOU/MLC  (where MLC is the user name)
permissions come as  - domain\LBV,domain\BBK,domain\EJQ,domain\SFV  

is it possible to convert them to email address or upn in the same go. i can do in a seperate script... but if possible to do the conversion on the fly and display as email address.

let me know or else i will accept solution and close this. appreciate the help.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41799468
Change line
Owner = ($R | get-recipient).Manager

Open in new window

To
Owner = (Get-Mailbox ($R | get-recipient).Manager ).PrimarySmtpAddress

Open in new window

0
 
LVL 40

Expert Comment

by:Subsun
ID: 41799482
This might run little faster..
$RMailbox = Get-Recipient -RecipientTypeDetails Sharedmailbox -ResultSize Unlimited
$(Foreach ($R in $RMailbox){
$St = $R | Get-MailboxStatistics 
	New-Object PSObject -Property @{
		Name = $R.Name
		Email = $R.PrimarySmtpAddress
		LastLoggedOnUserAccount = $St.LastLoggedOnUserAccount
		LastLogonTime  = $St.LastLogonTime
		LastLogoffTime = $St.LastLogoffTime
		FullMBXPerm = ($R | Get-MailboxPermission |?{$_.AccessRights -like "Fullaccess" -and $_.User -NotMatch "(Self|SYSTEM|^S-1-5-)"} | %{$_.User.ToString()}) -join ","
		SendAs = ($R | Get-ADPermission |?{$_.ExtendedRights -like "Send-as" -and $_.User -NotMatch "(Self|SYSTEM|^S-1-5-)"} | %{$_.User.ToString()}) -join ","
		Owner = (Get-Mailbox $R.Manager).PrimarySmtpAddress
	}
}) | Select Name,Email,Owner,FullMBXPerm,SendAS,Last*

Open in new window

0
 

Author Comment

by:ARM2009
ID: 41800058
this one does not work...

i think since the manager info is more like the OU path.... it cant read that identity unless you parse it.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41800340
It does work for me in my lab.
Does this gives result..

(Get-Mailbox $(Get-Recipient UserA).Manager).PrimarySmtpAddress

Open in new window

0
 

Author Comment

by:ARM2009
ID: 41800468
yep that works on an individual acct :)
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41800486
OK.. I cannot think of any reason for why it's failing for bulk user, as I am not able to reproduce the issue..
0
 

Author Comment

by:ARM2009
ID: 41800489
No worries. Thanka
0
 

Author Comment

by:ARM2009
ID: 41800510
this is is how i am testing now...

Owner = (Get-Mailbox $(Get-Recipient $R).Manager).PrimarySmtpAddress
0
 

Author Comment

by:ARM2009
ID: 41800514
error as below

Cannot process argument transformation on parameter 'Identity'. Cannot convert the "AdobeWorkflow" value of type "Deserialized.Microsoft.Exchange.Data.Directory.Management.Mailbox" to type "Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter".
    + CategoryInfo          : InvalidData: (:) [Get-Recipient], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-Recipient
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41800531
Owner = (Get-Mailbox $R.Manager).PrimarySmtpAddress

Owner = ($R.Manager | Get-Mailbox).PrimarySmtpAddress

Owner = (Get-Recipient $R.Manager).PrimarySmtpAddress

Owner = ($R.Manager | Get-Recipient).PrimarySmtpAddress

Owner = (Get-User $R.Manager).WindowsemailAddress

Owner = ($R.Manager | Get-User).WindowsemailAddress

Open in new window

All of these are working for me.. :-)
0
 

Author Comment

by:ARM2009
ID: 41804751
thanks....

this is what i get in the csv column for owner by using

Owner = (Get-Recipient $R.Manager -ResultSize Unlimited ).PrimarySmtpAddress

Owner
System.Object[]
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41804808
Try..
Owner = (Get-Recipient $R.Manager -ResultSize Unlimited ).PrimarySmtpAddress | Out-String

Open in new window

0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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