0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

共有メールボックスの棚卸しをしていて、「このメールボックス、結局誰がフルアクセス権を持っているんだっけ」「このユーザー、どの共有メールボックスの代理送信権限を持ってたっけ」と調べるのに手間取ったことはないでしょうか。

Exchange Onlineの権限は「フルアクセス許可」「メールボックス所有者として送信する権限(SendAs)」「代理人として送信する権限(SendOnBehalf)」の3種類があり、それぞれ確認するコマンドレットが異なります。全ユーザー分をまとめて棚卸しするスクリプトを整理してみたので共有します。3つの権限の違いについての詳しい解説は元記事にまとめています。

元記事: [【Microsoft365参考書】フルアクセス許可と代理送信権限の情報を取得するスクリプト]

3つの権限の違い

権限 できること 確認コマンドレット
フルアクセス許可 メールボックスへのアクセス(閲覧・操作) Get-MailboxPermission
メールボックス所有者として送信(SendAs) そのメールボックスの持ち主として送信 Get-RecipientPermission
代理人として送信(SendOnBehalf) 「〇〇の代理」として送信(送信者が明示される) メールボックスのGrantSendOnBehalfToプロパティ

SendAsとSendOnBehalfは似ていますが、送信されたメールの表示のされ方が異なる点が最大の違いです。

① フルアクセス許可を全ユーザー分棚卸しする

$mailboxes = Get-Mailbox -ResultSize Unlimited
$result = @()
foreach ($mbx in $mailboxes) {
    $permissions = Get-MailboxPermission -Identity $mbx.Identity | Where-Object {
        $_.AccessRights -contains "FullAccess"
    }
    if ($permissions) {
        $result += [PSCustomObject]@{
            MailboxAddress = $mbx.PrimarySmtpAddress
            User = $permissions.User
            AccessRights = $permissions.AccessRights
        }
    }
}
$result | Export-Csv -Path "C:\temp\FullAccessPermissions.csv" -NoTypeInformation

② SendAs権限を全ユーザー分棚卸しする

$mailboxes = Get-Mailbox -ResultSize Unlimited
$result = @()
foreach ($mbx in $mailboxes) {
    $permissions = Get-RecipientPermission -Identity $mbx.Identity | Where-Object {
        $_.Trustee -ne $null -and $_.AccessRights -contains "SendAs" -and $_.Trustee -ne "NT AUTHORITY\SELF"
    }
    foreach ($perm in $permissions) {
        $result += [PSCustomObject]@{
            MailboxAddress = $mbx.PrimarySmtpAddress
            Trustee = $perm.Trustee
            AccessRights = $perm.AccessRights -join ", "
        }
    }
}
$result | Export-Csv -Path "C:\temp\SendAsPermissions.csv" -NoTypeInformation -Encoding UTF8

Trustee -ne "NT AUTHORITY\SELF"で自分自身への権限(既定で誰もが持つ自分宛の送信権限)を除外しているのがポイントです。

③ SendOnBehalf権限を全ユーザー分棚卸しする

SendOnBehalfはメールボックスのGrantSendOnBehalfToプロパティに直接格納されているため、他の2つとは少し違うアプローチで取得します。

$mailboxes = Get-Mailbox -ResultSize Unlimited
$result = @()
foreach ($mbx in $mailboxes) {
    $delegates = $mbx.GrantSendOnBehalfTo
    if ($delegates) {
        foreach ($delegate in $delegates) {
            $resolved = Get-Recipient $delegate
            $result += [PSCustomObject]@{
                MailboxAddress = $mbx.PrimarySmtpAddress
                Delegate = $resolved.PrimarySmtpAddress
                PermissionType = "SendOnBehalf"
            }
        }
    }
}
$result | Export-Csv -Path "C:\temp\SendOnBehalfPermissions.csv" -NoTypeInformation -Encoding UTF8

特定ユーザーが持つ権限だけを調べたい場合

異動・退職者の権限整理では「このユーザーが持っている権限を全部洗い出したい」というニーズの方が多いと思います。その場合は、①のスクリプトのWhere-Object条件に-User "user@contoso.com"を追加する形で、対象ユーザーだけに絞り込めます(SendAs/SendOnBehalfも同様にTrustee/Delegateの値でフィルタする形に変更するだけです)。

おわりに

3つの権限をそれぞれ個別に確認していると時間がかかりますが、こうしてスクリプト化しておけば定期棚卸しがぐっと楽になります。特に退職者・異動者対応では「その人が持っていた権限を漏れなく確認する」ことが情報漏えい防止の観点でも重要です。より詳しい権限の仕組みの解説は元記事にまとめていますので、あわせてご覧ください。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?