locked
Output shared mailbox email address from get-exomailboxpermission RRS feed

  • Question

  • Hi I need to get the Shared mailboxes name, email address, AccessRights and user (who has the accessrights)

    I can find everything I want form this script except shared mailbox email address:

    Get-ExoMailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited |
     Get-ExoMailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} |
      Select Identity,User,@{Name=”AccessRights”;Expression={$_.AccessRights}} | Export-Csv C:\temp\sharedfolders_Permissions.csv -NoTypeInformation


    But I can't see a way to export the shared mailbox email address.

    I have been trying with PS objects:



    $Mailbox =  Get-ExoMailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited | Select PrimarySMTPAddress, userprincipalname, displayName
    if ($DisabledUsers -ne $null) {
        ForEach ($DisabledUser in $DisabledUsers) {
            $3 = Get-ExoMailboxPermission -Identity $DisabledUser.UserPrincipalName| where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false
    
            #Create new object for Reporting
            $obj = New-Object PSObject
            $obj | Add-Member -MemberType NoteProperty -Name "Shared Mailbox Name" -Value $Mailbox.Displayname
            $obj | Add-Member -MemberType NoteProperty -Name "Shared Mailbox Email Address" -Value $Mailbox.PrimarySmtpAddress
            $obj | Add-Member -MemberType NoteProperty -Name "AccessRights" -Value $($3.AccessRights)
            $obj | Add-Member -MemberType NoteProperty -Name "Access Username" -Value $($3.User)
    
            #Adds object to the log array
            $LogArray += $obj
      
                }
         }
         }


    But I cant get the results that show on screen to be captured so I can create a report....



    Thanks, M


    • Edited by Maelito Friday, January 24, 2020 4:05 PM Formating
    Friday, January 24, 2020 4:04 PM

Answers

  • Your question is too vague and your code is very old from PSv1.  Thisis how we would do this in teh current versions of PowerShell.

    $mailboxes = Get-ExoMailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited
    $mailboxes |
        ForEach-Object{
            $mb = $_
            Get-ExoMailboxPermission -Identity $DisabledUser.UserPrincipalName| 
                where {$_.user -ne 'NT AUTHORITY\SELF' -and $_.IsInherited -eq $false} |
                ForEach-Object{
                    [pscustomobject]@{
                        'Shared Mailbox Name' = $_.Displayname
                        'Shared Mailbox Email Address' = $_.PrimarySmtpAddress
                        'AccessRights' = $mb.AccessRights
                        'Access Username' = $mb.User
                    }
            }
        } |
        ConvertTo-Html |
        Out-File report.html
    .\report.html


    \_(ツ)_/

    • Proposed as answer by Sokratissz Friday, January 24, 2020 10:24 PM
    • Marked as answer by Maelito Sunday, January 26, 2020 11:20 AM
    Friday, January 24, 2020 6:35 PM

All replies

  • Your question is too vague and your code is very old from PSv1.  Thisis how we would do this in teh current versions of PowerShell.

    $mailboxes = Get-ExoMailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited
    $mailboxes |
        ForEach-Object{
            $mb = $_
            Get-ExoMailboxPermission -Identity $DisabledUser.UserPrincipalName| 
                where {$_.user -ne 'NT AUTHORITY\SELF' -and $_.IsInherited -eq $false} |
                ForEach-Object{
                    [pscustomobject]@{
                        'Shared Mailbox Name' = $_.Displayname
                        'Shared Mailbox Email Address' = $_.PrimarySmtpAddress
                        'AccessRights' = $mb.AccessRights
                        'Access Username' = $mb.User
                    }
            }
        } |
        ConvertTo-Html |
        Out-File report.html
    .\report.html


    \_(ツ)_/

    • Proposed as answer by Sokratissz Friday, January 24, 2020 10:24 PM
    • Marked as answer by Maelito Sunday, January 26, 2020 11:20 AM
    Friday, January 24, 2020 6:35 PM
  • JRV!!!! The legend!!!

    I follow you on here and try to learn from your posts - my work life is not 100% coding based so yeah, I do have some difficulties but I do try to learn on the job... once again I thank you for your post and hope you keep posting for a long time.

    I found this page which is very informative about psobjects. I will keep it under my learning favourites.

    Also I see that you exported to .html.... you have forgot out last encounter! :)

    \_(ツ)_/\_(ツ)_/\_(ツ)_/

    Thanks, M



    Maelito


    • Edited by Maelito Friday, January 24, 2020 10:04 PM \_(ツ)_/
    Friday, January 24, 2020 9:59 PM
  • JRV, 

    Don't really want to start a discussion here but this is how I changed your script to make it work for me:

    $mailboxes = Get-ExoMailbox -RecipientTypeDetails SharedMailbox -ResultSize:Unlimited | select UserprincipalName, PrimarySMTPAddress,name
    $mailboxes |
        ForEach-Object{
            $mb = $_
            Get-ExoMailboxPermission -Identity $_.userprincipalname|
                where {$_.user -ne 'NT AUTHORITY\SELF' -and $_.IsInherited -eq $false} |
                ForEach-Object{
                    [pscustomobject]@{
                        'Shared Mailbox Name' = $mb.Name
                        'Shared Mailbox Email Address' = $mb.PrimarySmtpAddress
                        'AccessRights' = [String]$_.AccessRights
                        'Access Username' = $_.User
                    }
            }
        } | OGV
        

    Without a doubt I will take this as a (another) lesson.

    Just for my benefit when would you use a foreach ($1 in $many) instead of a forach-obejct?

    Thanks, M


    Maelito

    Sunday, January 26, 2020 11:46 AM