Solved

script to get all Shared mailboxes and who has permisisons

Posted on 2016-07-19
8
23 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
  • 5
  • 3
8 Comments
 
LVL 30

Expert Comment

by:renazonse
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:renazonse
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
 

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 30

Assisted Solution

by:renazonse
renazonse 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
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…
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…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now