cascodigital/m365-admin-toolkit
GitHub: cascodigital/m365-admin-toolkit
面向 MSP 和企业管理员的 Microsoft 365 租户管理 PowerShell 脚本工具包,覆盖 Exchange 管理、安全审计、SharePoint 同步及系统运维等场景。
Stars: 0 | Forks: 0
# M365 管理工具包






用于管理 Microsoft 365 租户的 PowerShell 脚本。专为需要现成工具来进行审计、安全和用户管理的 MSP 和管理员而设计。
## 结构
```
m365-admin-toolkit/
├── exchange/ # Gestao de correio e aliases
├── security/ # MFA, senhas e Security Defaults
├── audit/ # Logs de logon, busca de arquivos e eventos
├── sharepoint/ # Gestao e sincronizacao de SharePoint/OneDrive
├── tools/ # Utilitarios (keyboard, ping, Office removal)
└── gpo/ # GPO exportada para auditoria de logons (importavel)
```
## Exchange
| 脚本 | 描述 |
|--------|-----------|
| `Set-CatchAllMailbox.ps1` | 创建动态组 + catch-all 规则,用于接收无目标收件人的电子邮件 |
| `Remove-Email.ps1` | 在租户中搜索并清除特定邮件 |
| `Set-MailAlias.ps1` | 管理别名并启用 SendFromAliasEnabled |
| `Get-Emails.ps1` | 列出租户中的所有地址(用户、组、别名) |
## 安全
| 脚本 | 描述 |
|--------|-----------|
| `Set-M365Passwords.ps1` | 批量生成并应用安全密码,支持导出 CSV |
| `Manage-SecurityDefaults-SMTP.ps1` | 切换 Security Defaults (MFA) + 按用户配置 SMTP AUTH |
| `Get-MfaComplianceReport.ps1` | MFA 合规性报告,过滤出真实用户 |
## 审计
| 脚本 | 描述 |
|--------|-----------|
| `Get-LogonEvents.ps1` | 对多台主机上的 4624 事件进行取证分析 |
| `Search-Files.ps1` | 按名称、扩展名或内容在 OneDrive 中搜索文件 |
| `Search-Events.ps1` | 按 Event ID 分析 Windows 日志并导出至 Excel |
## SharePoint
| 脚本 | 描述 |
|--------|-----------|
| `Sync-SharePointDeletion.ps1` | 删除 SharePoint 中本地源缺失的文件。在使用 SharePoint Migration Tool 迁移后非常有用,可保持目标与源(本地文件夹、网络共享、OneDrive 等)同步。在执行真正操作前具有模拟模式。 |
## 工具
| 脚本 | 描述 |
|--------|-----------|
| `Fix-KeyboardLayout.ps1` | 强制使用 ABNT2 并禁用布局切换热键 |
| `Monitor-Ping.ps1` | ICMP 延迟监控器,支持实时记录 CSV |
| `Remove-Office.ps1` | 彻底移除 Office 安装 |
| `Show-DiskUsage.ps1` | TreeSize 风格的 GUI。向 Windows 询问每个文件分配的物理大小(`GetCompressedFileSizeW`),与 TreeSize 的“Allocated”列一致:由操作系统处理压缩/sparse/hardlink,排除仅在云端的文件(OneDrive On-Demand)且不遍历 junctions。最大文件置顶,显示父级百分比,支持可导航树状图和右键删除。需要管理员权限。无需安装第三方软件。 |
## GPO
`gpo/` 文件夹包含一个用于登录审计的 GPO 备份,随时可通过 `Import-GPO` 在任何域中导入。无客户数据。
## 要求
- PowerShell 5.1+(推荐 7+)
- 模块: `Microsoft.Graph`, `ExchangeOnlineManagement`, `ImportExcel`
- 适当的权限 (Global Admin / Exchange Admin / Password Admin)
```
Install-Module Microsoft.Graph -Scope CurrentUser
Install-Module ExchangeOnlineManagement -Scope CurrentUser
Install-Module ImportExcel -Scope CurrentUser
```
## 使用方法
```
git clone https://github.com/cascodigital/m365-admin-toolkit.git
cd m365-admin-toolkit
# 执行所需的脚本
PowerShell -ExecutionPolicy Bypass -File .\exchange\Set-CatchAllMailbox.ps1
```
所有脚本均带有交互式提示和内部文档。
## 警告
- **`Set-M365Passwords.ps1`** 生成的 CSV 包含明文密码 —— 请妥善安全存储
- **`Remove-Email.ps1`** 执行的是不可逆清除 —— 请先在受控环境中测试
- **`Sync-SharePointDeletion.ps1`** 会永久删除文件 —— 务必先在模拟模式下运行 (`$ModoReal = $false`)
- **`Remove-Office.ps1`** 执行的是激进移除 —— 执行前请通知用户
- **`Show-DiskUsage.ps1`** 右键删除是永久性的(`Remove-Item -Recurse -Force`,不进回收站)—— 执行前请确认路径
由 **Casco Digital** 用 🐢(和咖啡)开发。
标签:AI合规, Exchange, IPv6, Libemu, Microsoft 365, PowerShell, 微软云, 系统运维, 脚本工具