将共享邮箱权限导出到 .csv
Export shared mailbox permissions to .csv
我需要学习如何制作一个脚本来获取我们公司中有权访问共享邮箱的所有用户。
例如:
共享邮箱:shared_admin@business.com
我想像这样导出为 .csv:
| Username | Access | Mailbox |
| john.peterson | Full Access | shared_admin@business.com |
| anne.wall | Full Access | shared_admin@business.com |
| jason.doe | Full Access | shared_admin@business.com |
| tim.carlson |Full Access | shared_admin@business.com |
首先安装 Exchange Online PowerShell module v2:
Install-Module -Name ExchangeOnlineManagement
那么下面的代码应该可以完成这项工作:
# Connect to Exchange Online
Connect-ExchangeOnline
# Retrieve mailbox permissions
$sharedMailbox = 'shared_admin@business.com'
$permissions = Get-MailboxPermission -Identity $sharedMailbox
# Format the permissions to have the column names you asked for
$formattedPermissions = $permissions `
| Select-Object -Property @{Name='Username';Expression={$_.User}},@{Name='Access';Expression={$_.AccessRights}},@{Name='Mailbox';Expression={$sharedMailbox}}
# Export to CSV, delimiter can be adjusted
$formattedPermissions | Export-Csv -Path permissions.csv -Delimiter ',' -Encoding UTF8 -NoTypeInformation
我需要学习如何制作一个脚本来获取我们公司中有权访问共享邮箱的所有用户。
例如:
共享邮箱:shared_admin@business.com
我想像这样导出为 .csv:
| Username | Access | Mailbox |
| john.peterson | Full Access | shared_admin@business.com |
| anne.wall | Full Access | shared_admin@business.com |
| jason.doe | Full Access | shared_admin@business.com |
| tim.carlson |Full Access | shared_admin@business.com |
首先安装 Exchange Online PowerShell module v2:
Install-Module -Name ExchangeOnlineManagement
那么下面的代码应该可以完成这项工作:
# Connect to Exchange Online
Connect-ExchangeOnline
# Retrieve mailbox permissions
$sharedMailbox = 'shared_admin@business.com'
$permissions = Get-MailboxPermission -Identity $sharedMailbox
# Format the permissions to have the column names you asked for
$formattedPermissions = $permissions `
| Select-Object -Property @{Name='Username';Expression={$_.User}},@{Name='Access';Expression={$_.AccessRights}},@{Name='Mailbox';Expression={$sharedMailbox}}
# Export to CSV, delimiter can be adjusted
$formattedPermissions | Export-Csv -Path permissions.csv -Delimiter ',' -Encoding UTF8 -NoTypeInformation