LoginSignup
3
7

More than 3 years have passed since last update.

office365のグループの配信メンバー一覧をサクッと取得したい

Last updated at Posted at 2020-10-01

「Aさんが受け取ってるメールリスト、全部俺も受け取れるようにしといて」
すごい簡単に言うじゃん…やるけど…

とりあえずグループがわかれば良い人向け

  1. Exchange管理センター
  2. 受信者
  3. グループ
  4. 「…」
  5. データをCSVファイルにエクスポート

配信メンバー一覧をPowerShellで取得する

Powershellからoffice365へ接続できるようにする下準備

Microsoft Online Services サインイン アシスタントの導入

DLして叩いてインストールする

Windows Azure Active Directory モジュールを導入する

powershellを管理者権限で起動して以下を実行。

Install-Module -Name AzureADPreview

信頼されていないリポジトリからモジュールをインストールするようにメッセージが表示されたら、「Y」と入力し、Enter を押す。

  • 「Install-Module」が使えないエラーが出る
    • 「Windows Management Framework」が入ってなさそうなのでインストールしてくること
      • この導入は以下条件を満たしていないと失敗します
        • インストール可能なOSであること
        • .NET Framework 4.5以上がインストールされていること
        • WMF 3.0がインストールされていないこと

powershellからoffice365に接続する

powershellでのスクリプト実行を許可する

Set-ExecutionPolicy RemoteSigned

office365へ接続する情報を指定する

以下を実行すると権限情報入力ダイアログが出現します。
管理者権限を持つユーザーIDとパスワードを入力してください。

$UserCredential = Get-Credential

※Enterを押すとすぐに確定扱いされて、「あぁパスワードの入力がまだなのに…」ということになります。
※最後に入力した情報が保持されるので、何回失敗しても平気

Sessionの確立

権限情報が間違っているとこの実行でエラーがでます。
間違っていないと何も出力されずに実行が完了します。

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

何も起きなければ以下を更に実行

Import-PSSession $Session -DisableNameChecking

グループメンバ情報を取得する

ここまでの接続が完了しているならば以下手順へ。

出力する項目情報を定義する

お好きにカスタムしてください。

$Temp = foreach ($i in Get-DistributionGroup -ResultSize Unlimited){Get-DistributionGroupMember -Identity $i.PrimarySmtpAddress -ResultSize Unlimited | select @{n="Name";e={$i.Name}},@{n="DistributionGroupName";e={$i.DisplayName}},@{n="Alias";e={$i.Alias}},@{n="DistributionGroupMailAddress";e={$i.PrimarySmtpAddress}},@{n="GroupType";e={$i.GroupType}},@{n="ManagedBy";e={$i.ManagedBy}},@{n="HiddenFromAddressListsEnabled";e={$i.HiddenFromAddressListsEnabled}},DisplayName,PrimarySmtpAddress}

定義した情報を出力する

出力先csvのパスは適宜変更すること。

$Temp | Export-Csv -Encoding UTF8 -NoTypeInformation -Path "C:\hogehoge\output.csv"

一覧が出る!!!嬉しい!!!!

忘れずにoffice365接続セッションを切る

Remove-PSSession $Session

共有メールボックスは???

うまいこと一覧でとれなかったけど、個別指定ならいける…
共有メールボックスに紐づくユーザ情報はGet-MailboxPermissionで取れるらしい。

これをtempに指定して先述の出力でOK

メンバー軸

hogehoge:メンバーのID

$Temp = Get-mailboxPermission -ResultSize Unlimited -identity * -User hogehoge

メールボックス軸

hogehogeあっとmailaddres.sample.com:メールボックスのアドレス

$Temp = Get-mailboxPermission -ResultSize Unlimited -identity hogehoge@mailaddres.sample.com

参考にさせて頂いたところ

https://bizlog.tech/exo-gpmem-export/
https://bizlog.tech/powershell-connect-office365/
https://qiita.com/opengl-8080/items/bb0f5e4f1c7ce045cc57
https://docs.microsoft.com/ja-jp/office365/enterprise/powershell/connect-to-office-365-powershell
https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/Get-MailboxPermission?view=exchange-ps

3
7
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
3
7