我想创建一个完整的邮箱权限报告并将其导出到 PowerShell 中的 CSV。
$report = @()
$mailboxes = Get-Mailbox -ResultSize unlimited -RecipientTypeDetails sharedmailbox
foreach ($mailbox in $mailboxes)
{
$permissions = Get-Mailbox $mailbox.PrimarySmtpAddress | Get-MailboxPermission | Select-Object user, accessrights
$users = $permissions.user
$accessRights = $permissions.accessrights
$sendAsPermissions = Get-Mailbox $mailbox.PrimarySmtpAddress | Get-ADPermission | Where-Object {$_.extendedrights -eq "send-as"} | select -ExpandProperty user
$sendOnBehalfPermissions = Get-Mailbox $mailbox.PrimarySmtpAddress | select -ExpandProperty grantsendonbehalfto
$properties = @{
Identity = $mailbox.PrimarySmtpAddress
Users = ($permissions.user -join "`n")
AccessRights = ($permissions.accessrights -join "`n")
SendAs = ($sendAsPermissions -join "`n")
SendOnBehalf = ($sendOnBehalfPermissions -join "`n")
}
$mailboxObject = New-Object -TypeName psobject -Property $properties
#$mailboxObject | select identity, users, accessrights | Export-Csv -Append -NoTypeInformation -Path c:\temp\test.csv
$mailboxObject | select identity, users, accessrights, sendas, sendonbehalf | out-gridview
}
gridview 准确地显示了我想要的内容,但我很难将其正确导出到 CSV。