A collection of PowerShell scripts for enterprise IT administration, covering Active Directory, Microsoft 365, Exchange Online, Entra ID, and Intune management tasks that i've created over the years.
- Table of Contents
- Features
- Getting Started
- Usage
- Configuration
- Folder Structure
- Modules and Functions
- Testing
- Logging and Troubleshooting
- Accessibility
- Contributing
- Changelog
- License
- Like to say thank you?
- Contact and Support
- ScriptLauncher: Build & Publish
- Active Directory Management: User creation, group management, computer organisation, and bulk operations
- Microsoft 365 Administration: Exchange Online mailbox management, quarantine handling, and transport rules
- Entra ID Integration: External user management, compromised account remediation, and identity operations
- Intune Device Management: Bulk device synchronisation, remediation scripts, and compliance monitoring
- General Utilities: Password generation, module management, and script selection tools
- OneDrive Administration: User content download and management capabilities
- Comprehensive Logging: Standardised logging across all scripts with detailed audit trails
- Error Handling: Robust error handling and retry logic for enterprise environments
- GUI Interfaces: User-friendly forms for complex administrative tasks
- PowerShell 7.0 or later
- Windows operating system
- Appropriate administrative permissions for target systems
- Required PowerShell modules (see individual scripts for specific requirements):
- Active Directory Module
- Exchange Online Management
- Microsoft Graph PowerShell SDK
- Microsoft.Graph.Intune
- MSOnline (where applicable)
-
Clone the repository:
git clone https://github.com/twcau/PowerShellScripting.git
-
Navigate to the project directory:
cd PowerShellScripting -
Review the script you want to use and install any required modules:
# Example: Install Exchange Online Management module Install-Module -Name ExchangeOnlineManagement -Force
-
Configure the scripts according to your environment (see Configuration section)
Each script is designed to be run independently. Navigate to the appropriate folder and execute the script:
# Example: Run user creation script
.\ad\user\creation\User-Creation.ps1
# Example: Run Intune bulk sync
.\intune\devices\Intune-BulkSync.ps1- Active Directory: Scripts for user and computer management in on-premises AD environments
- Exchange 365: Email and mailbox management for cloud and hybrid environments
- Entra ID: Identity and access management for Azure AD/Entra ID
- Intune: Mobile device management and compliance scripts
- General: Utility scripts for common administrative tasks
Many scripts include GUI interfaces for ease of use:
- User creation wizards with form-based input
- Device selection interfaces
- Progress indicators for long-running operations
The technician-friendly, menu-driven CLI for rapid Autopilot preparation and tracking lives here:
- Path:
intune/devices/autopilot-express/autopilot-express.ps1 - Manifest:
intune/devices/autopilot-express/autopilot-express.manifest.json - Runtime settings:
intune/devices/autopilot-express/autopilot-express.runtime.json
How to run:
- Open PowerShell 7 in the repository root.
- Run live mode with
intune/devices/autopilot-express/autopilot-express.ps1 -Mode Live. - Run demonstration mode with
intune/devices/autopilot-express/autopilot-express.ps1 -Mode Demo. - Select your current site when prompted (default is shown). The site code is used to enforce the Group Tag format.
- Use the on-screen menu to perform common tasks.
Current workflow coverage:
-
- Start work on a new device (capture Serial/CI, confirm Site, select Device Type, enforce Group Tag e.g.,
MI-Desktop)
- Start work on a new device (capture Serial/CI, confirm Site, select Device Type, enforce Group Tag e.g.,
-
- Run the manifest-driven Autopilot sequence (steps A-J cover Autopilot lookup, Intune cleanup, Group Tag application, deployment-profile confirmation, pre-provisioning group add/remove, userless-enrolment unblock, technician primary user, app retry, and final primary user assignment)
-
- Show outstanding work (devices with incomplete steps)
-
- Maintain device records
-
- Stats and summaries
-
- Enhancements (feature ideas; manifest-driven)
-
- Change site
-
- Build bench (positions grid with session persistence)
Mode behaviour:
Livemode uses browser-based Microsoft Graph sign-in only and validates the runtime JSON before continuing.Demomode simulates browser sign-in plus every manifest and Graph-backed action, while still persisting progress, recent-user choices, and resume state.- Live and demo sessions are isolated from each other and prompt to resume or archive-and-start-clean when prior state exists.
Build bench quick reference:
- Displays a grid of positions sized to your window, with centred position numbers and truncated values for readability.
I= Induct new deviceS= Start next step for a deviceV= View all actions for a deviceD= Dispatch and finish a deviceR= Remove from positionM= Move device between positionsE= Exit build bench view
Data and persistence:
- Session JSON is written to
data/when the repository path is writable. - If the repository path is read-only or behaves like a synced/reparse-point path that rejects new files, the script automatically falls back to
%LOCALAPPDATA%\PowerShellScriptingNew\AutopilotExpress\data. - Separate per-user files are maintained for live and demo device records, recent users, and build-bench state.
- Clean restarts archive the previous session automatically.
- Live mode also maintains
autopilot-master-audit.jsonfor manager review of technician actions and resulting device/user outcomes. - Group Tag is enforced as
SITECODE-DeviceType(no override) for consistency and policy compliance. - Required Graph scopes, modules, and tenant-specific values are externalised in the runtime JSON rather than hard-coded in the script body.
Some scripts may require environment-specific configuration. Review each script's header for specific requirements.
- Ensure you have appropriate administrative credentials
- Some scripts require multi-factor authentication (MFA)
- Consider using application passwords where applicable
Scripts include configurable parameters at the top of each file. Common customisations include:
- Domain names and organisational units
- Email domains and Exchange settings
- Logging paths and retention policies
- Timeout values and retry attempts
PowerShellScripting/
βββ ad/ # Active Directory scripts
β βββ computer/
β β βββ FindMachineOU.ps1 # Locate computer objects in AD
β βββ user/
β βββ creation/ # User account creation scripts
β β βββ AD-CopyGroups.ps1 # Copy group memberships
β β βββ User-Creation-Bulk.ps1 # Bulk user creation
β β βββ User-Creation.ps1 # Individual user creation with GUI
β β βββ User-Departure.ps1 # User departure processing
β βββ reconcillation/ # User account reconciliation
β βββ AD-Bulk-DepartedEmployeeReconcillation.ps1
β βββ Employee-Departure-Reconciliation.ps1
β βββ Employee-Listing.ps1
βββ e365/ # Exchange 365 scripts
β βββ E365-Mailbox-ConvertToShared.ps1 # Convert mailboxes to shared
β βββ E365-Quarantine-ExportRecord.ps1 # Export quarantine records
β βββ Exchange-QuarantineTABL-DataDownload.ps1
β βββ quarantine-to-block-v1.ps1 # Legacy quarantine triage and TABL workflow
β βββ quarantine-to-block.ps1 # Current quarantine triage, TABL, DNSBL, and deletion workflow
β βββ NewTransportRuleExecName.ps1 # Transport rule management
βββ entra/ # Entra ID (Azure AD) scripts
β βββ AutomateCompromisedAccountRemediation.ps1
β βββ Entra-UserExternal-Create.ps1 # External user creation
β βββ User-Management-External.ps1 # External user management
βββ general/ # General utility scripts
β βββ ScriptSelector.ps1 # Interactive script launcher
β βββ module-management/ # PowerShell module utilities
β β βββ Module-PowerShell7-Require.ps1
β β βββ Update-Module.ps1
β βββ password-generation/ # Password generation tools
β βββ Password-Generator-Silent.ps1
β βββ Password-Generator.ps1
βββ intune/ # Microsoft Intune scripts
β βββ devices/
β β βββ Intune-BulkSync.ps1 # Bulk device synchronisation
β βββ remediation/ # Intune remediation scripts
β βββ M365-VersionDetect.ps1 # M365 Apps version detection
β βββ M365-VersionRemediate.ps1 # M365 Apps version remediation
β βββ TeamsOld-Detect.ps1 # Legacy Teams detection
β βββ TeamsOld-Remediate.ps1 # Legacy Teams remediation
β βββ WinUpdate-23H2to24H2Force-Detect.ps1
β βββ WinUpdate-23H2to24H2Force-Remediate.ps1
β βββ WinUpdate-Detect.ps1 # Windows Update detection
β βββ WinUpdate-Pause-Detect.ps1 # Windows Update pause detection
β βββ WinUpdate-Pause-Remediate.ps1
β βββ WinUpdate-Remediate.ps1 # Windows Update remediation
βββ m365/ # Microsoft 365 scripts
βββ onedrive/ # OneDrive management scripts
β βββ M365-OneDrive-DownloadUserContents.ps1
βββ testing/ # Development and testing scripts
The scripts in this collection provide:
- User Management: Creation, modification, and departure processing
- Group Management: Membership copying and bulk operations
- Device Management: Synchronisation, detection, and remediation
- Security Operations: Compromised account handling and compliance monitoring
- Utility Functions: Password generation, module management, and system utilities
- User-Creation.ps1: Comprehensive user creation with GUI interface
- Intune-BulkSync.ps1: Mass device synchronisation for Intune environments
- Autopilot Express (CLI):
intune/devices/autopilot-express/autopilot-express.ps1β Menu-driven technician workflow with build bench and per-user persistence - quarantine-to-block.ps1: Interactive Exchange Online quarantine triage with guided release, TABL blocking, optional DNSBL submission, and optional deletion. DNSBL reporting is explicit opt-in.
- AutomateCompromisedAccountRemediation.ps1: Automated security response
- ScriptSelector.ps1: Interactive menu system for script selection
Testing scripts are located in the testing/ folder and include:
- Proof-of-concept implementations
- Version comparisons
- Experimental features
Before using scripts in production:
- Review the script header for version information and changelog
- Test in a non-production environment
- Verify all required modules are installed
- Check logging output for any warnings or errors
- For
e365/quarantine-to-block.ps1, verify release, TABL selection, and deletion behaviour in a test tenant first. DNSBL reporting now runs only when-ReportToDnsblis passed, or when defaults mode is explicitly requested and the saved DNSBL preference is enabled.
All scripts follow consistent logging practices:
- Log files stored in
$env:TEMPwith timestamps - Comprehensive error logging with context
- Success and failure reporting
- Progress indicators for long-running operations
- Module Import Errors: Ensure required PowerShell modules are installed
- Authentication Failures: Verify credentials and MFA settings
- Permission Errors: Check administrative rights for target systems
- Network Connectivity: Ensure access to required cloud services
- Quarantine-to-Block DNSBL Skips: DNSBL reporting is explicit opt-in. The script skips DNSBL submission unless
-ReportToDnsblis supplied, or defaults mode is explicitly requested with DNSBL enabled in the saved preferences.
- Check script headers for specific documentation links
- Review Microsoft documentation for API changes
- Consult PowerShell Gallery for module updates
This project is committed to accessibility and inclusive design:
- Scripts include progress indicators and clear status messages
- Documentation uses descriptive text for all functionality
- Error messages provide actionable guidance
- GUI interfaces follow accessibility best practices
- All documentation supports screen readers
Contributions to improve and expand this script collection are welcome. Please read the contribution guidelines:
- Code Standards: Follow PowerShell best practices and existing code style
- Documentation: Include comprehensive headers and inline comments
- Testing: Validate scripts in appropriate test environments
- Security: Ensure no hardcoded credentials or sensitive information
- Use Australian English (EN-AU) for documentation and comments
- Include proper error handling and logging
- Follow the established folder structure
- Update this README when adding new functionality
- 28/04/2026: Quarantine-to-Block now treats DNSBL reporting as explicit opt-in, keeps DNSBL scope roots separate during evaluation, expands function-level comment-based help across the script, and validates the workflow with dedicated regression tests for PSL loading, filter handling, export fallback, DNSBL gating, and block-expiry validation.
- 30/01/2026: Quarantine-to-Block workflow hardened: cancel on release grid now continues with zero releases; added
-IncludeProviderRootsto opt-in common provider roots for candidate selection; zero-candidate diagnostics preview added; DNSBL and deletion steps gated strictly on domain selections; dry-run guidance documented. - 6/06/2025: Enhanced user creation script with group copying improvements
- 27/03/2025: Added Clear Base User and Clear All User functionality
- 21/05/2025: Implemented base group validation and management
- 4/03/2025: Updated department listings for dynamic group memberships
See individual script headers for detailed version history and changelog information.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Copyright (c) 2025, Michael Harris, All rights reserved.
If these scripts have helped you in your IT administration tasks, consider:
- β Starring this repository
- π Reporting issues or suggesting improvements
- π Contributing to the documentation
- β Buy me a coffee to support continued development
- Michael Harris - @twcau
- Issues: Report bugs or request features via GitHub Issues
- Discussions: Join the conversation in GitHub Discussions
- Documentation: Review script headers and Microsoft documentation links
- Provide clear descriptions of issues with relevant log files
- Include PowerShell version and module information
- Specify the target environment (on-premises, cloud, hybrid)
- Follow the issue templates when reporting problems
This project follows Microsoft PowerShell best practices and maintains compatibility with enterprise IT environments.
The WPF-based ScriptLauncher app lives in ScriptLauncher/. It lets you organise and run PowerShell scripts by category, with per-user JSON config and optional elevation.
- Windows 10/11
- .NET SDK 8 (LTS) or 10 (latest). Verify installation:
dotnet --infoIf SDK is missing, install via Winget:
winget install Microsoft.DotNet.SDK.8
# or
winget install Microsoft.DotNet.SDK.10This repo includes global.json to prefer SDK 8 and roll forward to newer SDKs if needed.
dotnet build ScriptLauncher\ScriptLauncher.csproj -c Debug
dotnet run --project ScriptLauncher\ScriptLauncher.csprojFirst run will prompt to browse an existing config or create %AppData%\ScriptLauncher\scripts.json.
This repository includes automated CI for the WPF ScriptLauncher app. On pushes and pull requests to the default branches, GitHub Actions will:
- Build with warnings treated as errors to enforce quality (
-warnaserror). - Run an analyser sweep via
dotnet format analyzersat diagnostic verbosity. - Capture a verbose build (
-v diag) and upload both logs as workflow artefacts.
Workflow: .github/workflows/dotnet-ci.yml
Badge: See the status badge at the top of this README.
PR authors can download the CI logs for troubleshooting:
- Open your pull request on GitHub.
- Select the "Checks" tab, then choose ".NET Build & Analyzers (ScriptLauncher)".
- Open the latest workflow run for your commit.
- In the run summary, find the Artefacts section and download
scriptlauncher-logs. - The zip contains
analyzers-diagnostics.logandbuild-diagnostics.log.
dotnet publish ScriptLauncher\ScriptLauncher.csproj -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true
Compress-Archive -Path ScriptLauncher\bin\Release\net8.0-windows\win-x64\publish\* -DestinationPath ScriptLauncher-win-x64.zip -ForceDistribute the ScriptLauncher-win-x64.zip; users can run ScriptLauncher.exe. On first launch, the app will discover or create the per-user config.
- Commands-only menus: Menu items must use
Commandonly (no duplicateClick + Command). Dialogs open viaCommandBindingsinMainWindow.xaml.cs. - Single-press Esc close: Every modal window implements a native-handle ESC hook (
HwndSource.AddHookwithWM_KEYDOWN/VK_ESCAPE) to close immediately, regardless of focused control or dropdowns. - Owner assignment: All modal dialogs are opened with
Owner = MainWindowto ensure consistent modality and focus behaviour. - No global Esc interceptors: Avoid thread-level ESC interceptors; handle Esc per dialog to prevent unintended interactions.
- Accessibility: Provide access keys in dialog buttons and consistent keyboard navigation (e.g., Tab behaviour in grids).
These standards are enforced to maintain consistent, accessible UX and to prevent regressions like double-Esc or dialog respawn.
in MainWindow.xaml.cs.
- Single-press Esc close: Every modal window implements a native-handle ESC hook (
HwndSource.AddHookwithWM_KEYDOWN/VK_ESCAPE) to close immediately, regardless of focused control or dropdowns. - Owner assignment: All modal dialogs are opened with
Owner = MainWindowto ensure consistent modality and focus behaviour. - No global Esc interceptors: Avoid thread-level ESC interceptors; handle Esc per dialog to prevent unintended interactions.
- Accessibility: Provide access keys in dialog buttons and consistent keyboard navigation (e.g., Tab behaviour in grids).
These standards are enforced to maintain consistent, accessible UX and to prevent regressions like double-Esc or dialog respawn.