?
Solved

script to get all Shared mailboxes and who has permisisons

Posted on 2016-07-19
8
Medium Priority
?
46 Views
Last Modified: 2016-07-30
looking for a script via PS to get a list of all shared mailboxes and then also output who has full and/or sendas permissions.

on the output, need user samaccountname, upn and display name
0
Comment
Question by:ARM2009
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 30

Expert Comment

by:Britt Thompson
ID: 41719807
$boxes = Get-Mailbox | ?{$_.IsShared -eq $true}
$domain = "YOURDOMAIN\"
foreach($b in $boxes)
{
@"

----------------------- $($b.Alias) -----------------------
"@

    $fullperms = $b | Get-MailboxPermission | ?{$_.AccessRights -match "FullAccess" -and $_.IsInherited -eq $false -and $_.User -notlike "*NT AUTHORITY\SELF"} | 
        %{
            $id = (($_.User).ToString()).Replace($domain,"")
            Get-ADUser $id | %{ $_.Name + ", " + $_.SamAccountName + ", " + $_.UserPrincipalName + "; " }
         }
    $sendperms = $b | Get-ADPermission | ?{$_.ExtendedRights -match "Send-As" -and $_.IsInherited -eq $false -and $_.User -notlike "*NT AUTHORITY\SELF"} | 
        %{
            $id = (($_.User).ToString()).Replace($domain,"")
            Get-ADUser $id | %{ $_.Name + ", " + $_.SamAccountName + ", " + $_.UserPrincipalName + "; " }
         }

    Write-Host "Full Permissions: $fullperms"
    Write-Host "Send Permissions: $sendperms"
}

Open in new window

0
 

Author Comment

by:ARM2009
ID: 41719834
running from Exchange shell... get the following error. do I need to load AD cmdlets? also can this be dumped in a txt or csv file.

ForEach-Object : The term 'Get-ADUser' is not recognized as the name of a cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\****\2.ps1:11 char:10
+         % <<<< {
    + CategoryInfo          : ObjectNotFound: (Get-ADUser:String) [ForEach-Object], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.ForEachObjectCommand

ForEach-Object : The term 'Get-ADUser' is not recognized as the name of a cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\***\2.ps1:16 char:10
+         % <<<< {
    + CategoryInfo          : ObjectNotFound: (Get-ADUser:String) [ForEach-Object], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.ForEachObjectCommand

Full Permissions:
Send Permissions:
0
 
LVL 30

Expert Comment

by:Britt Thompson
ID: 41719838
Use Get-Mailbox in place of Get-ADUser


$boxes = Get-Mailbox | ?{$_.IsShared -eq $true}
$domain = "YOURDOMAIN\"
$CSV = "$env:USERPROFILE\Desktop\Permissions.csv"
$Out = @()
$Headers = @("Name","samAccountName","UPN")
foreach($b in $boxes)
{
@"

----------------------- $($b.Alias) -----------------------
"@

    $fullperms = $b | Get-MailboxPermission | ?{$_.AccessRights -match "FullAccess" -and $_.IsInherited -eq $false -and $_.User -notlike "*NT AUTHORITY\SELF"} | 
        %{
            $id = (($_.User).ToString()).Replace($domain,"")
            Get-Mailbox $id | %{ $Out += ,@($_.Name + "," + $_.SamAccountName + "," + $_.UserPrincipalName) }
         }
    $sendperms = $b | Get-ADPermission | ?{$_.ExtendedRights -match "Send-As" -and $_.IsInherited -eq $false -and $_.User -notlike "*NT AUTHORITY\SELF"} | 
        %{
            $id = (($_.User).ToString()).Replace($domain,"")
            Get-Mailbox $id | %{ $Out += ,@($_.Name + "," + $_.SamAccountName + "," + $_.UserPrincipalName) }
         }
}

$Cols = $Headers.Count
$Vals = @()
foreach ($Row in $Out)
{
    $Obj = New-Object PSObject
    for ($i=0;$i -lt $cols; $i++)
    {
        $Obj | Add-Member -MemberType NoteProperty -Name $Headers[$i] -Value $Row[$i]
    }
    $Vals+=$Obj
    $Obj = $null
}
$Vals | Export-CSV $CSV -NoTypeInformation

Open in new window

0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:ARM2009
ID: 41719846
runs with errors... but does output as well..

----------------------- sampleAlias-----------------------
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

eventually does output result...
0
 
LVL 30

Assisted Solution

by:Britt Thompson
Britt Thompson earned 2000 total points
ID: 41719852
See what happens if you put the commands on one line

$fullperms = $b | Get-MailboxPermission | ?{$_.AccessRights -match "FullAccess" -and $_.IsInherited -eq $false -and $_.User -notlike "*NT AUTHORITY\SELF"} | %{$id = (($_.User).ToString()).Replace($domain,""); Get-Mailbox $id | %{ $Out += ,@($_.Name + "," + $_.SamAccountName + "," + $_.UserPrincipalName) }}

Could be some copy/paste translation issue
0
 

Author Comment

by:ARM2009
ID: 41719890
errors as below

shared mailbox is Letters
----------------------- Letters -----------------------
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

The operation couldn't be performed because object 'S-1-5-21-343818398-1202660629-682003330-488641' couldn't be found o
n 'DC.test.com'.
    + CategoryInfo          : NotSpecified: (:) [Get-Mailbox], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : B94CB0B2,Microsoft.Exchange.Management.RecipientTasks.GetMailbox

The operation couldn't be performed because object 'S-1-5-21-343818398-1202660629-682003330-531918' couldn't be found o
n 'DC.test.com'
    + CategoryInfo          : NotSpecified: (:) [Get-Mailbox], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : 89944120,Microsoft.Exchange.Management.RecipientTasks.GetMailbox


as u can tell.. this time around I had not data at all
0
 

Accepted Solution

by:
ARM2009 earned 0 total points
ID: 41727760
this is what worked for me....

$RunUsers = Import-CSV C:\shared.csv

$RunUsers | % { $mID = $_.AcctID; Get-MailboxPermission -identity $mID | 
        Where-Object{($_.AccessRights -match "FullAccess") -and -not 
        ($_.User -like "NT AUTHORITY\SELF") -and -not 
        ($_.User -like "domain\Domain Admins") -and -not 
        ($_.User -like "domain\Enterprise Admins") -and -not 
        ($_.User -like "domain\Organization Management") -and -not 
        ($_.User -like "domain\Exchange Servers") -and -not 
        ($_.User -like "domain\Exchange Trusted Subsystem") -and -not 
        ($_.User -like "S-1-5-21-*") -and -not 
        ($_.User -like "NT AUTHORITY\SYSTEM")} |
       
        select Identity, User |
        export-csv C:\perms.csv -Append -Force }
0
 

Author Closing Comment

by:ARM2009
ID: 41735650
the script works as expected for the results.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

752 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