Solved

script to get all Shared mailboxes and who has permisisons

Posted on 2016-07-19
8
38 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 eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
how to add IIS SMTP to handle application/Scanner relays into office 365.

724 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