#
AutomateCompromisedAccountRemediation.ps1
Purpose Dependencies Function Usage Inputs Variables Command Line Flags Outputs Notes
#
Purpose
Automates Microsoft 365/Entra ID (Azure AD) compromised account remediation using 8 best-practice steps. Handles module installation, logs all actions, and supports both interactive and bulk operation.
#
Dependencies
- PowerShell 7.0 or later (Install Guide)
- Microsoft Graph module (Microsoft Docs)
- Exchange Online Management module (Microsoft Docs)
- Require-Pwsh7.ps1 (local script, must be accessible and dot-sourced)
#
Function
- Loads and validates required modules (installs if missing, with user confirmation).
- Connects to Microsoft Graph and Exchange Online (supports certificate-based auth).
- Accepts user(s) via parameter, CSV, or interactive prompt.
- Presents a menu of 8 remediation actions (disable user, sign out, reset password, review MFA, disable inbox rules, review/remove forwarding, get audit log) or "all".
- Performs selected actions for each user, logging results and errors to output files.
- Exports status, password, invalid user, and error logs to the script directory.
- Offers to open the output file at completion.
#
Usage
./AutomateCompromisedAccountRemediation.ps1
The script is interactive and supports both single and bulk operation. User(s) can be provided via parameter, CSV, or prompt.
#
Inputs
- UserPrincipalName(s) via parameter, CSV file, or interactive prompt
- Optional: TenantId, ClientId, CertificateThumbprint for CBA
#
Variables
$UPNs
: Array of user principal names to remediate$Actions
: Array of selected remediation actions$ExportCSV
,$PasswordLogFile
,$InvalidUserLogFile
,$ErrorsLogFile
: Output file paths
#
Command Line Flags
None for standard use. (Parameters are supported for automation.)
#
Outputs
- CSV and TXT logs of all actions, passwords, invalid users, and errors
- Console and pop-up feedback for each step
#
Notes
- Requires PowerShell 7, Microsoft Graph, and Exchange Online Management modules
- Local script Require-Pwsh7.ps1 must be accessible
- See script header for official documentation links and further details