ms365-tenant-manager について
Microsoft 365のグローバル管理者向けに、テナント設定、ユーザーライフサイクル、セキュリティポリシーのガイダンスと自動化を提供するスキルです。PowerShellの例と、反復可能な設定・ユーザー管理スクリプトを生成するPythonツールを含みます。
主な機能
- 01テナント設定チェックリストと生成ツール
- 02ユーザーの一括作成とオフボーディング
- 03条件付きアクセスとMFAのワークフロー
- 04セキュリティ監査とSecure Score確認
- 05PowerShellスクリプト生成
活用シーン
- 01新しいMicrosoft 365テナントの設定計画
- 02構造化データからのユーザー登録
- 03ポリシー監査とMFA適用の準備
- 04ユーザー退職時の処理とライセンス管理
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ alirezarezvani/ claude-skills --skill ms365-tenant-managerインストール後、Claude Code で/ms365-tenant-managerを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
expected_output.jsonsample_input.jsonreferences/powershell-templates.mdsecurity-policies.mdtroubleshooting.mdscripts/powershell_generator.pytenant_setup.pyuser_management.py詳細
Microsoft 365 Tenant Manager
テナントのセットアップ、ユーザーのライフサイクル、セキュリティポリシー、組織の最適化を管理する Microsoft 365 グローバル管理者向けの専門的なガイダンスと自動化を提供します。
クイックスタート
セキュリティ監査を実行する
Connect-MgGraph -Scopes "Directory.Read.All","Policy.Read.All","AuditLog.Read.All"
Get-MgSubscribedSku | Select-Object SkuPartNumber, ConsumedUnits, @{N="Total";E={$_.PrepaidUnits.Enabled}}
Get-MgPolicyAuthorizationPolicy | Select-Object AllowInvitesFrom, DefaultUserRolePermissions
CSV からユーザーを一括プロビジョニングする
# CSV columns: DisplayName, UserPrincipalName, Department, LicenseSku
Import-Csv .\new_users.csv | ForEach-Object {
$passwordProfile = @{ Password = (New-Guid).ToString().Substring(0,16) + "!"; ForceChangePasswordNextSignIn = $true }
New-MgUser -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName `
-Department $_.Department -AccountEnabled -PasswordProfile $passwordProfile
}
条件付きアクセス ポリシーを作成する(管理者に MFA を適用)
$adminRoles = (Get-MgDirectoryRole | Where-Object { $_.DisplayName -match "Admin" }).Id
$policy = @{
DisplayName = "Require MFA for Admins"
State = "enabledForReportingButNotEnforced" # Start in report-only mode
Conditions = @{ Users = @{ IncludeRoles = $adminRoles } }
GrantControls = @{ Operator = "OR"; BuiltInControls = @("mfa") }
}
New-MgIdentityConditionalAccessPolicy -BodyParameter $policy
同梱の Python ジェネレーター
3 つの標準ライブラリツールを使うと、PowerShell の成果物を決定論的に生成できます。一括処理や繰り返し可能な作業では、スクリプトを手書きするのではなく、これらのツールを優先してください。サンプル入力:sample_input.json、想定される形式:expected_output.json。
# Tenant setup: checklist + DNS records + license plan (JSON), or the full setup script
python3 scripts/tenant_setup.py --config sample_input.json --format json -o tenant_plan.json
python3 scripts/tenant_setup.py --config sample_input.json --format powershell -o tenant_setup.ps1
# User lifecycle: validate first, then generate creation/offboarding scripts
python3 scripts/user_management.py --domain acme.com --action validate --users users.json
python3 scripts/user_management.py --domain acme.com --action create --users users.json -o create_users.ps1
python3 scripts/user_management.py --domain acme.com --action offboard --user-email [email protected] -o offboard.ps1
# Admin scripts: CA policy / security audit / bulk licensing
python3 scripts/powershell_generator.py --tenant-domain acme.com --task conditional-access --policy-config policy.json -o ca_policy.ps1
python3 scripts/powershell_generator.py --tenant-domain acme.com --task security-audit -o audit.ps1
python3 scripts/powershell_generator.py --tenant-domain acme.com --task bulk-license --users-csv users.csv --license-sku ENTERPRISEPACK -o licenses.ps1
ゲート: ユーザーを作成する場合は、最初に --action validate を実行し、すべてのエントリで "is_valid": true が報告されることを確認してから、作成スクリプトを生成してください。テナントで実行する前に、生成されたすべての .ps1 を以下のワークフローに照らして確認してください。
ワークフロー
ワークフロー 1:新しいテナントのセットアップ
ステップ 1:セットアップチェックリストを生成する
python3 scripts/tenant_setup.py --config tenant.json --format json を実行し、setup_checklist の各フェーズに沿って作業します。dns_records はステップ 2 で、license_recommendations はライセンスのワークフローで使用します。
プロビジョニングを開始する前に、前提条件を確認します。
- グローバル管理者アカウントが作成され、MFA で保護されている
- カスタムドメインを購入済みで、DNS レコードを編集できる
- ライセンス SKU を確認済み(E3 と E5 の機能要件を把握している)
ステップ 2:DNS レコードを構成して確認する
# After adding the domain in the M365 admin center, verify propagation before proceeding
$domain = "company.com"
Resolve-DnsName -Name "_msdcs.$domain" -Type NS -ErrorAction SilentlyContinue
# Also run from a shell prompt:
# nslookup -type=MX company.com
# nslookup -type=TXT company.com # confirm SPF record
一括ユーザー作成の前に、DNS の伝播を最大 48 時間待ちます。
ステップ 3:セキュリティベースラインを適用する
# Disable legacy authentication (blocks Basic Auth protocols)
$policy = @{
DisplayName = "Block Legacy Authentication"
State = "enabled"
Conditions = @{ ClientAppTypes = @("exchangeActiveSync","other") }
GrantControls = @{ Operator = "OR"; BuiltInControls = @("block") }
}
New-MgIdentityConditionalAccessPolicy -BodyParameter $policy
# Enable unified audit log
Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true
ステップ 4:ユーザーをプロビジョニングする
$licenseSku = (Get-MgSubscribedSku | Where-Object { $_.SkuPartNumber -eq "ENTERPRISEPACK" }).SkuId
Import-Csv .\employees.csv | ForEach-Object {
try {
$user = New-MgUser -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName `
-AccountEnabled -PasswordProfile @{ Password = (New-Guid).ToString().Substring(0,12)+"!"; ForceChangePasswordNextSignIn = $true }
Set-MgUserLicense -UserId $user.Id -AddLicenses @(@{ SkuId = $licenseSku }) -RemoveLicenses @()
Write-Host "Provisioned: $($_.UserPrincipalName)"
} catch {
Write-Warning "Failed $($_.UserPrincipalName): $_"
}
}
検証: M365 管理ポータルで 3~5 個のアカウントを抜き取り確認し、ライセンスが「Active」と表示されていることを確認します。
ワークフロー 2:セキュリティの強化
ステップ 1:セキュリティ監査を実行する
Connect-MgGraph -Scopes "Directory.Read.All","Policy.Read.All","AuditLog.Read.All","Reports.Read.All"
# Export Conditional Access policy inventory
Get-MgIdentityConditionalAccessPolicy | Select-Object DisplayName, State |
Export-Csv .\ca_policies.csv -NoTypeInformation
# Find accounts without MFA registered
$report = Get-MgReportAuthenticationMethodUserRegistrationDetail
$report | Where-Object { -not $_.IsMfaRegistered } |
Select-Object UserPrincipalName, IsMfaRegistered |
Export-Csv .\no_mfa_users.csv -NoTypeInformation
Write-Host "Audit complete. Review ca_policies.csv and no_mfa_users.csv."
ステップ 2:MFA ポリシーを作成する(最初はレポート専用)
$policy = @{
DisplayName = "Require MFA All Users"
State = "enabledForReportingButNotEnforced"
Conditions = @{ Users = @{ IncludeUsers = @("All") } }
GrantControls = @{ Operator = "OR"; BuiltInControls = @("mfa") }
}
New-MgIdentityConditionalAccessPolicy -BodyParameter $policy
検証: 48 時間後に Entra ID のサインインログを確認し、想定されるユーザーにチャレンジが表示されることを確認してから、State を "enabled" に変更します。
ステップ 3:セキュアスコアを確認する
# Retrieve current Secure Score and top improvement actions
Get-MgSecuritySecureScore -Top 1 | Select-Object CurrentScore, MaxScore, ActiveUserCount
Get-MgSecuritySecureScoreControlProfile | Sort-Object -Property ActionType |
Select-Object Title, ImplementationStatus, MaxScore | Format-Table -AutoSize
ワークフロー 3:ユーザーのオフボーディング
ステップ 1:サインインをブロックし、セッションを取り消す
$upn = "[email protected]"
$user = Get-MgUser -Filter "userPrincipalName eq '$upn'"
# Block sign-in immediately
Update-MgUser -UserId $user.Id -AccountEnabled:$false
# Revoke all active tokens
Invoke-MgInvalidateAllUserRefreshToken -UserId $user.Id
Write-Host "Sign-in blocked and sessions revoked for $upn"
ステップ 2:-WhatIf でプレビューする(ライセンスの削除)
# Identify assigned licenses
$licenses = (Get-MgUserLicenseDetail -UserId $user.Id).SkuId
# Dry-run: print what would be removed
$licenses | ForEach-Object { Write-Host "[WhatIf] Would remove SKU: $_" }
ステップ 3:オフボーディングを実行する
# Remove licenses
Set-MgUserLicense -UserId $user.Id -AddLicenses @() -RemoveLicenses $licenses
# Convert mailbox to shared (requires ExchangeOnlineManagement module)
Set-Mailbox -Identity $upn -Type Shared
# Remove from all groups
Get-MgUserMemberOf -UserId $user.Id | ForEach-Object {
try { Remove-MgGroupMemberByRef -GroupId $_.Id -DirectoryObjectId $user.Id } catch {}
}
Write-Host "Offboarding complete for $upn"
検証: M365 管理ポータルで、アカウントが「Blocked」と表示され、アクティブなライセンスがなく、メールボックスの種類が「Shared」であることを確認します。
ベストプラクティス
テナントのセットアップ
- ユーザーを追加する前に MFA を有効にする
- 条件付きアクセス用に名前付きの場所を構成する
- PIM を使用して、管理者アカウントを分ける
- ユーザーを一括作成する前に、カスタムドメインを確認する(DNS の伝播も確認する)
- Microsoft Secure Score の推奨事項を適用する
セキュリティ運用
- 条件付きアクセス ポリシーは、レポート専用モードで開始する
- 新しいポリシーを適用する前に、サインインログを 48 時間確認する
- スクリプトに認証情報をハードコードしない — Azure Key Vault または
Get-Credentialを使用する - すべての操作で統合監査ログを有効にする
- 四半期ごとにセキュリティレビューとセキュアスコアの確認を実施する
PowerShell の自動化
- 従来の MSOnline よりも Microsoft Graph(
Microsoft.Graphモジュール)を優先する - エラー処理に
try/catchブロックを含める - 監査証跡として
Write-Host/Write-Warningによるログ記録を実装する - 一括で破壊的な操作を行う前に、
-WhatIfまたはドライランの出力を使用する - まず本番環境以外のテナントでテストする
リファレンスガイド
references/powershell-templates.md
- すぐに使えるスクリプトテンプレート
- 条件付きアクセス ポリシーの例
- ユーザーを一括プロビジョニングするスクリプト
- セキュリティ監査スクリプト
references/security-policies.md
- 条件付きアクセスの構成
- MFA の適用戦略
- DLP と保持ポリシー
- セキュリティベースラインの設定
references/troubleshooting.md
- よくあるエラーの解決方法
- PowerShell モジュールの問題
- 権限に関するトラブルシューティング
- DNS 伝播の問題
制限事項
| 制約 | 影響 |
|---|---|
| グローバル管理者が必要 | テナントの完全なセットアップには最高レベルの権限が必要です |
| API レート制限 | 一括操作がスロットリングされる場合があります |
| ライセンスの依存関係 | 高度な機能には E3/E5 が必要です |
| ハイブリッド環境 | オンプレミスの AD には追加の設定が必要です |
| PowerShell の前提条件 | Microsoft.Graph モジュールが必要です |
必要な PowerShell モジュール
Install-Module Microsoft.Graph -Scope CurrentUser
Install-Module ExchangeOnlineManagement -Scope CurrentUser
Install-Module MicrosoftTeams -Scope CurrentUser
必要な権限
- グローバル管理者 — テナントの完全なセットアップ
- ユーザー管理者 — ユーザー管理
- セキュリティ管理者 — セキュリティポリシー
- Exchange 管理者 — メールボックス管理