{"slug":"ms365-tenant-manager","title":"ms365-tenant-manager","summary":"Use for Microsoft 365 tenant administration (Entra ID users, Exchange Online, Teams, licenses, Conditional Access, compliance reports). Plans setup with tenant_setup.py, bulk-manages users with user_management.py and generates PowerShell with powershell_generator.py.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-02T16:53:21.463145Z","repo":{"url":"https://github.com/beginwithu/agent-skills","stars":11,"forks":2,"license":"MIT","updatedAt":"2026-12-02T16:37:11Z"},"bodyHtml":"<hr>\n<h2>name: ms365-tenant-manager\ndescription: \"Use for Microsoft 365 tenant administration (Entra ID users, Exchange Online, Teams, licenses, Conditional Access, compliance reports). Plans setup with tenant_setup.py, bulk-manages users with user_management.py and generates PowerShell with powershell_generator.py.\"</h2>\n<h1>Microsoft 365 Tenant Manager</h1>\n<p>Expert guidance and automation for Microsoft 365 Global Administrators managing tenant setup, user lifecycle, security policies, and organizational optimization.</p>\n<hr>\n<h2>Quick Start</h2>\n<h3>Run a Security Audit</h3>\n<pre><code>Connect-MgGraph -Scopes \"Directory.Read.All\",\"Policy.Read.All\",\"AuditLog.Read.All\"\nGet-MgSubscribedSku | Select-Object SkuPartNumber, ConsumedUnits, @{N=\"Total\";E={$_.PrepaidUnits.Enabled}}\nGet-MgPolicyAuthorizationPolicy | Select-Object AllowInvitesFrom, DefaultUserRolePermissions\n</code></pre>\n<h3>Bulk Provision Users from CSV</h3>\n<pre><code># CSV columns: DisplayName, UserPrincipalName, Department, LicenseSku\nImport-Csv .\\new_users.csv | ForEach-Object {\n    $passwordProfile = @{ Password = (New-Guid).ToString().Substring(0,16) + \"!\"; ForceChangePasswordNextSignIn = $true }\n    New-MgUser -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName `\n               -Department $_.Department -AccountEnabled -PasswordProfile $passwordProfile\n}\n</code></pre>\n<h3>Create a Conditional Access Policy (MFA for Admins)</h3>\n<pre><code>$adminRoles = (Get-MgDirectoryRole | Where-Object { $_.DisplayName -match \"Admin\" }).Id\n$policy = @{\n    DisplayName = \"Require MFA for Admins\"\n    State = \"enabledForReportingButNotEnforced\"   # Start in report-only mode\n    Conditions = @{ Users = @{ IncludeRoles = $adminRoles } }\n    GrantControls = @{ Operator = \"OR\"; BuiltInControls = @(\"mfa\") }\n}\nNew-MgIdentityConditionalAccessPolicy -BodyParameter $policy\n</code></pre>\n<h3>Bundled Python Generators</h3>\n<p>Three stdlib tools generate the PowerShell artifacts deterministically — prefer them over hand-writing scripts for bulk/repeatable work. Sample input: <code>sample_input.json</code>; expected shape: <code>expected_output.json</code>.</p>\n<pre><code># Tenant setup: checklist + DNS records + license plan (JSON), or the full setup script\npython3 scripts/tenant_setup.py --config sample_input.json --format json -o tenant_plan.json\npython3 scripts/tenant_setup.py --config sample_input.json --format powershell -o tenant_setup.ps1\n\n# User lifecycle: validate first, then generate creation/offboarding scripts\npython3 scripts/user_management.py --domain acme.com --action validate --users users.json\npython3 scripts/user_management.py --domain acme.com --action create --users users.json -o create_users.ps1\npython3 scripts/user_management.py --domain acme.com --action offboard --user-email jane@acme.com -o offboard.ps1\n\n# Admin scripts: CA policy / security audit / bulk licensing\npython3 scripts/powershell_generator.py --tenant-domain acme.com --task conditional-access --policy-config policy.json -o ca_policy.ps1\npython3 scripts/powershell_generator.py --tenant-domain acme.com --task security-audit -o audit.ps1\npython3 scripts/powershell_generator.py --tenant-domain acme.com --task bulk-license --users-csv users.csv --license-sku ENTERPRISEPACK -o licenses.ps1\n</code></pre>\n<p><strong>Gate:</strong> for user creation, run <code>--action validate</code> first and require every entry to report <code>\"is_valid\": true</code> before generating the creation script. Review every generated <code>.ps1</code> against the workflows below before running it in the tenant.</p>\n<hr>\n<h2>Workflows</h2>\n<h3>Workflow 1: New Tenant Setup</h3>\n<p><strong>Step 1: Generate Setup Checklist</strong></p>\n<p>Run <code>python3 scripts/tenant_setup.py --config tenant.json --format json</code> and work through <code>setup_checklist</code> phase by phase; <code>dns_records</code> feeds Step 2 and <code>license_recommendations</code> feeds the licensing workflow.</p>\n<p>Confirm prerequisites before provisioning:</p>\n<ul>\n<li>Global Admin account created and secured with MFA</li>\n<li>Custom domain purchased and accessible for DNS edits</li>\n<li>License SKUs confirmed (E3 vs E5 feature requirements noted)</li>\n</ul>\n<p><strong>Step 2: Configure and Verify DNS Records</strong></p>\n<pre><code># After adding the domain in the M365 admin center, verify propagation before proceeding\n$domain = \"company.com\"\nResolve-DnsName -Name \"_msdcs.$domain\" -Type NS -ErrorAction SilentlyContinue\n# Also run from a shell prompt:\n# nslookup -type=MX company.com\n# nslookup -type=TXT company.com   # confirm SPF record\n</code></pre>\n<p>Wait for DNS propagation (up to 48 h) before bulk user creation.</p>\n<p><strong>Step 3: Apply Security Baseline</strong></p>\n<pre><code># Disable legacy authentication (blocks Basic Auth protocols)\n$policy = @{\n    DisplayName = \"Block Legacy Authentication\"\n    State = \"enabled\"\n    Conditions = @{ ClientAppTypes = @(\"exchangeActiveSync\",\"other\") }\n    GrantControls = @{ Operator = \"OR\"; BuiltInControls = @(\"block\") }\n}\nNew-MgIdentityConditionalAccessPolicy -BodyParameter $policy\n\n# Enable unified audit log\nSet-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true\n</code></pre>\n<p><strong>Step 4: Provision Users</strong></p>\n<pre><code>$licenseSku = (Get-MgSubscribedSku | Where-Object { $_.SkuPartNumber -eq \"ENTERPRISEPACK\" }).SkuId\n\nImport-Csv .\\employees.csv | ForEach-Object {\n    try {\n        $user = New-MgUser -DisplayName $_.DisplayName -UserPrincipalName $_.UserPrincipalName `\n                           -AccountEnabled -PasswordProfile @{ Password = (New-Guid).ToString().Substring(0,12)+\"!\"; ForceChangePasswordNextSignIn = $true }\n        Set-MgUserLicense -UserId $user.Id -AddLicenses @(@{ SkuId = $licenseSku }) -RemoveLicenses @()\n        Write-Host \"Provisioned: $($_.UserPrincipalName)\"\n    } catch {\n        Write-Warning \"Failed $($_.UserPrincipalName): $_\"\n    }\n}\n</code></pre>\n<p><strong>Validation:</strong> Spot-check 3–5 accounts in the M365 admin portal; confirm licenses show \"Active.\"</p>\n<hr>\n<h3>Workflow 2: Security Hardening</h3>\n<p><strong>Step 1: Run Security Audit</strong></p>\n<pre><code>Connect-MgGraph -Scopes \"Directory.Read.All\",\"Policy.Read.All\",\"AuditLog.Read.All\",\"Reports.Read.All\"\n\n# Export Conditional Access policy inventory\nGet-MgIdentityConditionalAccessPolicy | Select-Object DisplayName, State |\n    Export-Csv .\\ca_policies.csv -NoTypeInformation\n\n# Find accounts without MFA registered\n$report = Get-MgReportAuthenticationMethodUserRegistrationDetail\n$report | Where-Object { -not $_.IsMfaRegistered } |\n    Select-Object UserPrincipalName, IsMfaRegistered |\n    Export-Csv .\\no_mfa_users.csv -NoTypeInformation\n\nWrite-Host \"Audit complete. Review ca_policies.csv and no_mfa_users.csv.\"\n</code></pre>\n<p><strong>Step 2: Create MFA Policy (report-only first)</strong></p>\n<pre><code>$policy = @{\n    DisplayName = \"Require MFA All Users\"\n    State = \"enabledForReportingButNotEnforced\"\n    Conditions = @{ Users = @{ IncludeUsers = @(\"All\") } }\n    GrantControls = @{ Operator = \"OR\"; BuiltInControls = @(\"mfa\") }\n}\nNew-MgIdentityConditionalAccessPolicy -BodyParameter $policy\n</code></pre>\n<p><strong>Validation:</strong> After 48 h, review Sign-in logs in Entra ID; confirm expected users would be challenged, then change <code>State</code> to <code>\"enabled\"</code>.</p>\n<p><strong>Step 3: Review Secure Score</strong></p>\n<pre><code># Retrieve current Secure Score and top improvement actions\nGet-MgSecuritySecureScore -Top 1 | Select-Object CurrentScore, MaxScore, ActiveUserCount\nGet-MgSecuritySecureScoreControlProfile | Sort-Object -Property ActionType |\n    Select-Object Title, ImplementationStatus, MaxScore | Format-Table -AutoSize\n</code></pre>\n<hr>\n<h3>Workflow 3: User Offboarding</h3>\n<p><strong>Step 1: Block Sign-in and Revoke Sessions</strong></p>\n<pre><code>$upn = \"departing.user@company.com\"\n$user = Get-MgUser -Filter \"userPrincipalName eq '$upn'\"\n\n# Block sign-in immediately\nUpdate-MgUser -UserId $user.Id -AccountEnabled:$false\n\n# Revoke all active tokens\nInvoke-MgInvalidateAllUserRefreshToken -UserId $user.Id\nWrite-Host \"Sign-in blocked and sessions revoked for $upn\"\n</code></pre>\n<p><strong>Step 2: Preview with -WhatIf (license removal)</strong></p>\n<pre><code># Identify assigned licenses\n$licenses = (Get-MgUserLicenseDetail -UserId $user.Id).SkuId\n\n# Dry-run: print what would be removed\n$licenses | ForEach-Object { Write-Host \"[WhatIf] Would remove SKU: $_\" }\n</code></pre>\n<p><strong>Step 3: Execute Offboarding</strong></p>\n<pre><code># Remove licenses\nSet-MgUserLicense -UserId $user.Id -AddLicenses @() -RemoveLicenses $licenses\n\n# Convert mailbox to shared (requires ExchangeOnlineManagement module)\nSet-Mailbox -Identity $upn -Type Shared\n\n# Remove from all groups\nGet-MgUserMemberOf -UserId $user.Id | ForEach-Object {\n    try { Remove-MgGroupMemberByRef -GroupId $_.Id -DirectoryObjectId $user.Id } catch {}\n}\nWrite-Host \"Offboarding complete for $upn\"\n</code></pre>\n<p><strong>Validation:</strong> Confirm in the M365 admin portal that the account shows \"Blocked,\" has no active licenses, and the mailbox type is \"Shared.\"</p>\n<hr>\n<h2>Best Practices</h2>\n<h3>Tenant Setup</h3>\n<ol>\n<li>Enable MFA before adding users</li>\n<li>Configure named locations for Conditional Access</li>\n<li>Use separate admin accounts with PIM</li>\n<li>Verify custom domains (and DNS propagation) before bulk user creation</li>\n<li>Apply Microsoft Secure Score recommendations</li>\n</ol>\n<h3>Security Operations</h3>\n<ol>\n<li>Start Conditional Access policies in report-only mode</li>\n<li>Review Sign-in logs for 48 h before enforcing a new policy</li>\n<li>Never hardcode credentials in scripts — use Azure Key Vault or <code>Get-Credential</code></li>\n<li>Enable unified audit logging for all operations</li>\n<li>Conduct quarterly security reviews and Secure Score check-ins</li>\n</ol>\n<h3>PowerShell Automation</h3>\n<ol>\n<li>Prefer Microsoft Graph (<code>Microsoft.Graph</code> module) over legacy MSOnline</li>\n<li>Include <code>try/catch</code> blocks for error handling</li>\n<li>Implement <code>Write-Host</code>/<code>Write-Warning</code> logging for audit trails</li>\n<li>Use <code>-WhatIf</code> or dry-run output before bulk destructive operations</li>\n<li>Test in a non-production tenant first</li>\n</ol>\n<hr>\n<h2>Reference Guides</h2>\n<p><strong>references/powershell-templates.md</strong></p>\n<ul>\n<li>Ready-to-use script templates</li>\n<li>Conditional Access policy examples</li>\n<li>Bulk user provisioning scripts</li>\n<li>Security audit scripts</li>\n</ul>\n<p><strong>references/security-policies.md</strong></p>\n<ul>\n<li>Conditional Access configuration</li>\n<li>MFA enforcement strategies</li>\n<li>DLP and retention policies</li>\n<li>Security baseline settings</li>\n</ul>\n<p><strong>references/troubleshooting.md</strong></p>\n<ul>\n<li>Common error resolutions</li>\n<li>PowerShell module issues</li>\n<li>Permission troubleshooting</li>\n<li>DNS propagation problems</li>\n</ul>\n<hr>\n<h2>Limitations</h2>\n<table>\n<thead>\n<tr>\n<th>Constraint</th>\n<th>Impact</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Global Admin required</td>\n<td>Full tenant setup needs highest privilege</td>\n</tr>\n<tr>\n<td>API rate limits</td>\n<td>Bulk operations may be throttled</td>\n</tr>\n<tr>\n<td>License dependencies</td>\n<td>E3/E5 required for advanced features</td>\n</tr>\n<tr>\n<td>Hybrid scenarios</td>\n<td>On-premises AD needs additional configuration</td>\n</tr>\n<tr>\n<td>PowerShell prerequisites</td>\n<td>Microsoft.Graph module required</td>\n</tr>\n</tbody>\n</table>\n<h3>Required PowerShell Modules</h3>\n<pre><code>Install-Module Microsoft.Graph -Scope CurrentUser\nInstall-Module ExchangeOnlineManagement -Scope CurrentUser\nInstall-Module MicrosoftTeams -Scope CurrentUser\n</code></pre>\n<h3>Required Permissions</h3>\n<ul>\n<li><strong>Global Administrator</strong> — Full tenant setup</li>\n<li><strong>User Administrator</strong> — User management</li>\n<li><strong>Security Administrator</strong> — Security policies</li>\n<li><strong>Exchange Administrator</strong> — Mailbox management</li>\n</ul>\n","files":[{"path":"expected_output.json","sizeBytes":2052,"isText":true},{"path":"LICENSE","sizeBytes":1072,"isText":false},{"path":"references/powershell-templates.md","sizeBytes":21511,"isText":true},{"path":"references/security-policies.md","sizeBytes":8792,"isText":true},{"path":"references/troubleshooting.md","sizeBytes":9809,"isText":true},{"path":"sample_input.json","sizeBytes":471,"isText":true},{"path":"scripts/powershell_generator.py","sizeBytes":16042,"isText":true},{"path":"scripts/tenant_setup.py","sizeBytes":18444,"isText":true},{"path":"scripts/user_management.py","sizeBytes":18709,"isText":true},{"path":"SKILL.md","sizeBytes":10881,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-02T16:55:10.476713Z","sha256":"B768048DEA2B2DB773C382B8D4E5F55DA11E4DCE707F7E70A2A9F0375B4A8138","sizeBytes":33971},"review":null,"source":{"repositoryUrl":"https://github.com/beginwithu/agent-skills","path":"skills/ms365-tenant-manager","license":"MIT","commit":"a960304c52212f2e845067047f5cefc0c594d787","subtreeSha":"5D14CCE2A3291D4035C05C0A30DB14DFE4BD1806095338D2E422E9380DF6A0FE","lastSyncedAt":"2026-12-02T16:52:59.20206Z"},"reviewedAt":"2026-12-02T16:58:34.691243Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/beginwithu/agent-skills/tree/main/skills/ms365-tenant-manager"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install beginwithu-agent-skills@llmmart"},{"target":"git","command":"git clone https://github.com/beginwithu/agent-skills.git"}]}