MS365共有メールボックス365グループ一覧取得方法¶
実施内容¶
1. 実施手順①(Exchange Online / 共有メールボックス 等)¶
目的
共有メールボックスを一覧化し、管理資料を作成する¶
実施コマンド
- 接続
Connect-ExchangeOnline
- 一覧取得
# フルアクセス
Get-Mailbox -RecipientTypeDetails SharedMailbox | ForEach-Object {
$mb = $_
Get-MailboxPermission $mb.Identity |
Where-Object {$_.User -notlike "NT AUTHORITY*"} |
Select-Object @{n="MailboxDisplayName";e={$mb.DisplayName}},
@{n="MailboxSMTP";e={$mb.PrimarySmtpAddress}},
User, AccessRights
} | Export-Csv ".\SharedMailbox_Members_FullAccess.csv" -NoTypeInformation -Encoding UTF8
# Send As
Get-Mailbox -RecipientTypeDetails SharedMailbox | ForEach-Object {
$mb = $_
Get-RecipientPermission $mb.Identity |
Where-Object {$_.Trustee -notlike "NT AUTHORITY*"} |
Select-Object @{n="MailboxDisplayName";e={$mb.DisplayName}},
@{n="MailboxSMTP";e={$mb.PrimarySmtpAddress}},
Trustee, AccessRights
} | Export-Csv ".\SharedMailbox_Members_SendAs.csv" -NoTypeInformation -Encoding UTF8
# 代理送信(GrantSendOnBehalfTo は配列)
Get-Mailbox -RecipientTypeDetails SharedMailbox | ForEach-Object {
$mb = $_
[pscustomobject]@{
MailboxDisplayName = $mb.DisplayName
MailboxSMTP = $mb.PrimarySmtpAddress
GrantSendOnBehalfTo= ($mb.GrantSendOnBehalfTo -join '; ')
}
} | Export-Csv ".\SharedMailbox_Members_SendOnBehalf.csv" -NoTypeInformation -Encoding UTF8
Connect-ExchangeOnline
# フルアクセス
Get-Mailbox -RecipientTypeDetails SharedMailbox | ForEach-Object {
$mb = $_
Get-MailboxPermission $mb.Identity |
Where-Object {$_.User -notlike "NT AUTHORITY*"} |
Select-Object @{n="MailboxDisplayName";e={$mb.DisplayName}},
@{n="MailboxSMTP";e={$mb.PrimarySmtpAddress}},
User, AccessRights
} | Export-Csv ".\SharedMailbox_Members_FullAccess.csv" -NoTypeInformation -Encoding UTF8
# Send As
Get-Mailbox -RecipientTypeDetails SharedMailbox | ForEach-Object {
$mb = $_
Get-RecipientPermission $mb.Identity |
Where-Object {$_.Trustee -notlike "NT AUTHORITY*"} |
Select-Object @{n="MailboxDisplayName";e={$mb.DisplayName}},
@{n="MailboxSMTP";e={$mb.PrimarySmtpAddress}},
Trustee, AccessRights
} | Export-Csv ".\SharedMailbox_Members_SendAs.csv" -NoTypeInformation -Encoding UTF8
# 代理送信(GrantSendOnBehalfTo は配列)
Get-Mailbox -RecipientTypeDetails SharedMailbox | ForEach-Object {
$mb = $_
[pscustomobject]@{
MailboxDisplayName = $mb.DisplayName
MailboxSMTP = $mb.PrimarySmtpAddress
GrantSendOnBehalfTo= ($mb.GrantSendOnBehalfTo -join '; ')
}
} | Export-Csv ".\SharedMailbox_Members_SendOnBehalf.csv" -NoTypeInformation -Encoding UTF8
出力物
ファイル名:SharedMailbox_List.csv
保存先:\server\path\YYYYMMDD\
出力項目:
- DisplayName
- PrimarySmtpAddress
2. 実施手順②(Microsoft Teams)¶
目的
Microsoft Teams のチーム一覧を取得し、利用状況を把握する¶
実施コマンド
- 接続
Connect-MicrosoftTeams
- チーム一覧取得(オーナー一覧)
$rows = @()
$teams = Get-Team
foreach ($t in $teams) {
$owners = Get-TeamUser -GroupId $t.GroupId -Role Owner -ErrorAction SilentlyContinue
foreach ($o in $owners) {
$rows += [pscustomobject]@{
TeamDisplayName = $t.DisplayName
TeamGroupId = $t.GroupId
Role = "Owner"
User = $o.User
}
}
}
$rows | Export-Csv ".\Teams_Owners.csv" -NoTypeInformation -Encoding UTF8
- チーム一覧取得(メンバー一覧)
$rows = @()
$teams = Get-Team
foreach ($t in $teams) {
$members = Get-TeamUser -GroupId $t.GroupId -Role Member -ErrorAction SilentlyContinue
foreach ($m in $members) {
$rows += [pscustomobject]@{
TeamDisplayName = $t.DisplayName
TeamGroupId = $t.GroupId
Role = "Member"
User = $m.User
}
}
}
$rows | Export-Csv ".\Teams_Members.csv" -NoTypeInformation -Encoding UTF8
Connect-MicrosoftTeams
$rows = @()
$teams = Get-Team
foreach ($t in $teams) {
$owners = Get-TeamUser -GroupId $t.GroupId -Role Owner -ErrorAction SilentlyContinue
foreach ($o in $owners) {
$rows += [pscustomobject]@{
TeamDisplayName = $t.DisplayName
TeamGroupId = $t.GroupId
Role = "Owner"
User = $o.User
}
}
}
$rows | Export-Csv ".\Teams_Owners.csv" -NoTypeInformation -Encoding UTF8
$rows = @()
$teams = Get-Team
foreach ($t in $teams) {
$members = Get-TeamUser -GroupId $t.GroupId -Role Member -ErrorAction SilentlyContinue
foreach ($m in $members) {
$rows += [pscustomobject]@{
TeamDisplayName = $t.DisplayName
TeamGroupId = $t.GroupId
Role = "Member"
User = $m.User
}
}
}
$rows | Export-Csv ".\Teams_Members.csv" -NoTypeInformation -Encoding UTF8