Micorosoft ExchangeOnlineの設定でWebからポチポチはWebのレスポンスが悪いし設定の階層も深くとても面倒に感じました。PowerShellでアカウントの作成・CSVから配布リスト(メーリングリストと同意)を作ってしまう作戦。何度もトライアンドエラー繰り返してやっとこさ意図した結果になりました。以下の記載は備忘録ですが正確性は×です。何度か繰り返して記事精度を上げてまいります。
参考にさせていただいたマイクロソフト社のページ
事前準備
アカウント情報(以下は当然ながら実在しない当記事の例となります
表示名:ほげ製作所_ほげ田ほげ男
メールアドレス:hogeo@hoge.jp
パスワード:Passw@d
配布リスト(メーリングリストと同意)のCSV
初回のみモジュールのインストール必要かも(曖昧ポイント)
1 |
PS C:\Windows\system32> Install-Module MSOnline |
PowerShellを管理者モードで起動しExchangeOnlineに接続
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. 新しいクロスプラットフォームの PowerShell をお試しください https://aka.ms/pscore6 PS C:\WINDOWS\system32> connect-msolservice PS C:\WINDOWS\system32> connect-exchangeonline ---------------------------------------------------------------------------- The module allows access to all existing remote PowerShell (V1) cmdlets in addition to the 9 new, faster, and more reliable cmdlets. |--------------------------------------------------------------------------| | Old Cmdlets | New/Reliable/Faster Cmdlets | |--------------------------------------------------------------------------| | Get-CASMailbox | Get-EXOCASMailbox | | Get-Mailbox | Get-EXOMailbox | | Get-MailboxFolderPermission | Get-EXOMailboxFolderPermission | | Get-MailboxFolderStatistics | Get-EXOMailboxFolderStatistics | | Get-MailboxPermission | Get-EXOMailboxPermission | | Get-MailboxStatistics | Get-EXOMailboxStatistics | | Get-MobileDeviceStatistics | Get-EXOMobileDeviceStatistics | | Get-Recipient | Get-EXORecipient | | Get-RecipientPermission | Get-EXORecipientPermission | |--------------------------------------------------------------------------| To get additional information, run: Get-Help Connect-ExchangeOnline or check https://aka.ms/exops-docs Send your product improvement suggestions and feedback to exocmdletpreview@service.microsoft.com. For issues related to the module, contact Microsoft support. Don't use the feedback alias for problems or support issues. ---------------------------------------------------------------------------- |
いろいろなコマンドを試してExchangeOnlineには接続ができたので確定した方法ではないです。途中OAuthの認証?(これも曖昧)がはいります。
所持ライセンスの確認
1 2 3 4 5 6 7 |
PS C:\WINDOWS\system32> Get-MsolAccountSku AccountSkuId ActiveUnits WarningUnits ConsumedUnits ------------ ----------- ------------ ------------- reseller-account:FLOW_FREE 10000 0 0 reseller-account:EXCHANGESTANDARD 2 0 2 reseller-account:O365_BUSINESS_PREMIUM 50 0 48 |
48/50消費している
ユーザアカウント追加ここが肝
20230426更新 -ForceChangePassword $false の付与が運用的には必要でした。このオプションなしだとOfficeライセンスは認証されるのですが、OneDriveアクセス時パスワードのリセットが必要だと怒られてしまう。発行済みパスワードでOneDriveも任所するためです。
こちらの解説ページ

Set-MsolUserPassword (MSOnline)
Set-MsolUserPassword コマンドレットは、ユーザーのパスワードをリセットします。 このコマンドレットは、標準 ID を持つユーザーのみに使用できます。
1 2 3 4 5 |
New-MsolUser -DisplayName "ほげ製作所_ほげ田ほげ男" -FirstName ほげ男 -LastName ほげ田 -UserPrincipalName hogeo@hoge.jp -UsageLocation JP -LicenseAssignment reseller-account:O365_BUSINESS_PREMIUM -Password Passw@d -ForceChangePassword $false Password UserPrincipalName DisplayName isLicensed -------- ----------------- ----------- ---------- Passw@rd hogeo@hoge.jp ほげ製作所_ほげ田ほげ男 True |
ライセンスの消費確認
1 2 3 4 5 6 7 |
PS C:\WINDOWS\system32> Get-MsolAccountSku AccountSkuId ActiveUnits WarningUnits ConsumedUnits ------------ ----------- ------------ ------------- reseller-account:FLOW_FREE 10000 0 0 reseller-account:EXCHANGESTANDARD 2 0 2 reseller-account:O365_BUSINESS_PREMIUM 50 0 49 |
49/50となっている→正常1消費
Microsoft365管理センターから確認(非必須)
配布グループメンバー追加のCSV
AddGroupMember.csvとして作成
Identity | PrimarySmtpAddress |
haifulist1@hoge.jp | hogeo@hoge.jp |
haifulist2@hoge.jp | hogeo@hoge.jp |
配布グループメンバーの追加
1 |
Import-Csv D:\Microsoft365\PowerShellBat\AddGroupMember.csv | foreach { Add-DistributionGroupMember -Identity $_.Identity -Member $_.PrimarySmtpAddress -BypassSecurityGroupManagerCheck -Confirm:$False} |
コメント