Senior Systems Engineer
Senior Systems Engineer

Reputation: 1139

Modifying PowerShell script to display RecipientDetailsType and FullAccess permission

I need to modify the below PowerShell script to show two more column called RecipientDetailsType and FullAccess.

The below PowerShell code is already working, but I need to get two more additional columns.

$DataPath = "C:\TEMP\Delegates-Results.csv"
$Results = @()
$MailboxUsers = Get-Mailbox -ResultSize Unlimited -Database CAB-DB02

foreach($user in $mailboxusers) {
    $UPN = $user.UserPrincipalName
    $MbxStats = Get-MailboxStatistics $UPN
    $UserNotes = Get-User $UPN

    $delegates = @(Get-MailboxPermission -Identity $UPN | 
                    Where-Object { ($_.AccessRights -like "*FullAccess*") -and 
                                   (-not $_.IsInherited) -and 
                                   ($_.User.toString() -ne "NT AUTHORITY\SELF") -and 
                                   ($_.User.toString() -notlike '*Discovery Management*') } |
                    Select-Object @{Name='Delegate'; Expression={(Get-Recipient $_.User.toString()).DisplayName}}, 
                                  @{Name='AccessRights';Expression={$_.AccessRights -join ', '}})

     $Properties = @{
          Name = $user.name
          PrimarySmtpAddress = $user.PrimarySmtpAddress
          RecipientTypeDetails = $user.RecipientTypeDetails
          FullAccess = $user.FullAccess
          UPN = $UPN
          Alias = $user.alias
          OU = $user.organizationalunit
          Server = $MbxStats.servername
          Database = $MbxStats.databasename
          TotaItemSize = [math]::Round(($MbxStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)
          Delegates  = $delegates.Delegate -join ', '
          Notes = $UserNotes.Notes
      }
    $Results += New-Object psobject -Property $properties
}
$Results | Sort-Object -Property TotaItemSize | Select-Object Name,UPN,Alias,RecipientTypeDetails,FullAccess,OU,Server,Database,TotaItemSize,Notes,Delegates | Export-Csv -notypeinformation -Path $DataPath

Upvotes: 0

Views: 158

Answers (1)

Ian Manning
Ian Manning

Reputation: 81

Have you tried modifying $Properties to:

     $Properties = @{
          Name = $user.name
          PrimarySmtpAddress = $user.PrimarySmtpAddress
          RecipientDetailsType = $user.RecepientDetailsType
          FullAccess = $user.FullAccess
          UPN = $UPN
          Alias = $user.alias
          OU = $user.organizationalunit
          Server = $MbxStats.servername
          Database = $MbxStats.databasename
          TotaItemSize = [math]::Round(($MbxStats.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)
          Notes = $UserNotes.Notes
      }

$Results | Sort-Object -Property TotaItemSize | Select-Object Name,UPN,Alias,RecepientDetailsType,FullAccess,OU,Server,Database,TotaItemSize,Notes | Export-Csv -notypeinformation -Path $DataPath

If that doesn't work, let me know and I'll try it in our Exchange environment.

Upvotes: 2

Related Questions