0
votes

I am using Exchange 2010 and trying to run a PowerShell to export all users that have a User mailbox, I am using the PowerShell below

Get-Mailbox -resultsize unlimited -recipienttypedetails UserMailbox | Get-MailboxPermission | export-csv c:\User_mailbox.csv -NoTypeInformation

However our environment hasn't been consistent when creating User Mailboxes, there are some Shared Mailboxes that appear as User Mailboxes when I look through the above-exported file.

Is there a way I can add a filter, attribute or pipe in the PowerShell command so only the 'User' field pulls data that are numeric values and not alpha values?

This is because I know a User Mailbox will only have numbers as their SamAccountname example 11368 and won't be joe.bloggs.

Thanks

1

1 Answers

0
votes

I think you may need to explicitly filter the Shared Mailboxes out:

Get-Mailbox -resultsize Unlimited -RecipientTypeDetails UserMailbox | 
    Where-Object { @($_.RecipientTypeDetails) -notcontains 'SharedMailbox' } | 
    Get-MailboxPermission | 
    Export-Csv c:\User_mailbox.csv -NoTypeInformation

Perhaps also the -Filter works more precise in your case:

Get-Mailbox -ResultSize Unlimited -Filter "RecipientTypeDetails -eq 'UserMailbox'" 

Edit

To also filter for the SamAccountName to be numeric, you can do something like this (untested):

Get-Mailbox -resultsize Unlimited -RecipientTypeDetails UserMailbox | 
    Where-Object { @($_.RecipientTypeDetails) -notcontains 'SharedMailbox' -and $_.SamAccountName -match '^\d+$'} | 
    Get-MailboxPermission | 
    Export-Csv c:\User_mailbox.csv -NoTypeInformation

or by using -Filter

Get-Mailbox -ResultSize Unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (SamAccountName -match '^\d+$')}