# Agent Guide: macOS Intune Management Toolkit > This file is written for AI coding agents. It assumes no prior knowledge of the project. Refer to `README.md`, `CHANGELOG_macOS_IntuneToolkit.md`, and `ReleaseNotes.md` for human-facing documentation. ## Project overview This repository is **macOS Intune Management** (also referred to as the IntuneManagement toolkit). It is a cross-platform, headless, PowerShell-first CLI for exporting, importing, migrating, and managing Microsoft Intune policies across tenants. - **Current version:** `4.1.0` (see `VERSION`). - **Primary workflow:** export policies from a source tenant as JSON, optionally capture assignments, then import them into a target tenant with app-only, browser, or device-code authentication. - **Additional capabilities:** declarative baseline deployment from YAML, bulk assignment management, backup/restore of assignments, bulk device operations, policy rename, CSV/Markdown reporting from local backups, and a CIS M365 rapid baseline for tenant-level workloads. - **Important historical note:** the old WPF UI surface has been removed. The repo is intentionally CLI-first and headless. There is no compiled application, no `pyproject.toml`/`package.json`/`Cargo.toml`/`Makefile`, and no CI/CD pipeline. The project is a collection of interpreted PowerShell modules/scripts with supporting Python utilities. ## Technology stack - **PowerShell 7+ (`pwsh`)** — required runtime. Some launcher files declare `#requires -Version 5.1`, but headless scripts and the runtime target PowerShell 7 behaviors. - **Microsoft Graph** — all tenant operations call the Graph `beta` (or optionally `v1.0`) endpoints. - **MSAL.NET** — authentication is handled via `Microsoft.Identity.Client.dll` (shipped in `Bin/`). C# helpers in `CS/` are compiled at runtime with `Add-Type` when proxy or token-cache support is needed. - **Python 3** — optional reporting utilities and CIS PDF conversion (`Scripts/*.py`). A local virtual environment `.venv-pdf` exists for PDF-specific dependencies (`pypdf`, `markdown-it`). - **YAML** — baseline manifests are authored in YAML and consumed by `powershell-yaml`. - **Optional `fzf`** — used by the TUI launchers for interactive menus; falls back to numbered prompts if missing. ### Required / optional dependencies | Dependency | Where used | How to install | |---|---|---| | PowerShell 7+ | Everything | `brew install powershell` / `winget install Microsoft.PowerShell` | | `Microsoft.Graph.Authentication` & `Microsoft.Graph.Applications` | `Initialize-IntuneAuth.ps1` | `Install-Module Microsoft.Graph -Scope CurrentUser -Force` | | `powershell-yaml` | `Deploy-IntuneBaseline.ps1` | Script prompts to install; or `Install-Module powershell-yaml -Scope CurrentUser -Force` | | `fzf` | TUI menus | `brew install fzf`, `apt install fzf`, `winget install junegunn.fzf` | | Python 3 + `pypdf`/`markdown-it` | CIS PDF conversion (`_ConvertFrom-CISPDF.py`) | Recreate `.venv-pdf`: `python3 -m venv .venv-pdf && .venv-pdf/bin/pip install pypdf markdown-it` | ## Architecture and module organization ```text . ├── Start-IntuneToolkit.ps1 # Unified terminal UI launcher (recommended entry point) ├── Core.psm1 # Headless runtime helpers, settings, logging, module loader ├── Runtime/ │ ├── IntuneManagement.Runtime.psd1 # Module manifest │ └── IntuneManagement.Runtime.psm1 # Thin bootstrap: sets globals and starts Core app ├── Headless/ │ ├── IntuneManagement.Headless.psd1 │ └── IntuneManagement.Headless.psm1 # Adapter: default object types, Export/Import/Action wrappers ├── Extensions/ # Loaded automatically by Core.psm1 │ ├── MSGraph.psm1 # Graph API layer, object-type registry, import/export logic │ ├── MSALAuthentication.psm1 # MSAL auth (app-only, browser, device code) │ └── EndpointManager.psm1 # Intune view definitions and per-type lifecycle hooks ├── Scripts/ # User-facing entry scripts and private helpers │ ├── Start-HeadlessIntune.ps1 # Single-action wrapper with optional TUI │ ├── Export-Policies.ps1 │ ├── Import-Policies.ps1 │ ├── Initialize-IntuneAuth.ps1 # One-time Entra app + secret setup │ ├── Deploy-IntuneBaseline.ps1 # YAML-driven baseline deployer │ ├── ConvertTo-IntuneBaseline.ps1 # Export folder → baseline skeleton │ ├── *_Bulk*.ps1 # Assignments, rename, device operations │ ├── *.py # Reporting and PDF conversion utilities │ └── Private/ │ └── Start-IntuneManagementTui.ps1 ├── Baselines/ # Example and generated baseline manifests │ ├── OpenIntuneBaseline.example.yaml │ ├── CISM365-v7.example.yaml │ ├── CISM365-v7-Generated.yaml │ └── M365-CIS-Rapid/ # Config-driven tenant-level baseline ├── Bin/ # MSAL DLLs ├── CS/ # C# helper source compiled at runtime └── .venv-pdf/ # Isolated Python venv for PDF processing ``` ### How the pieces fit together 1. An entry script (`Start-IntuneToolkit.ps1`, `Export-Policies.ps1`, etc.) imports `Headless/IntuneManagement.Headless.psd1`. 2. The Headless module builds a JSON batch configuration describing the requested export/import action and writes it to a temporary file. 3. It imports `Runtime/IntuneManagement.Runtime.psd1` and calls `Initialize-IntuneManagementRuntime`, which sets global authentication variables and invokes `Start-CoreApp` from `Core.psm1`. 4. `Core.psm1` loads every `*.psm1` in `Extensions/` and dispatches module lifecycle hooks (`Invoke-InitializeModule`, `Invoke-SilentBatchJob`). 5. `Extensions/MSGraph.psm1` and `Extensions/EndpointManager.psm1` do the actual Graph calls and policy handling. ### Object-type registry Intune object types are declared as `Add-ViewItem` entries in `Extensions/EndpointManager.psm1`. The headless default list (returned by `Get-DefaultIntunePolicyObjectTypes`) contains roughly 45 types, including: - `DeviceConfiguration`, `SettingsCatalog`, `AdministrativeTemplates` - `CompliancePolicies`, `CompliancePoliciesV2`, `EndpointSecurity`, `DeviceManagementIntents` - `PolicySets`, `Applications`, `AppProtection`, `AppConfigurationManagedDevice` - `ConditionalAccess`, `NamedLocations`, `TermsOfUse` - Many more (scripts, branding, enrollment, update policies, etc.) You can override the list per-run with the `-ObjectTypes` parameter. ## Configuration and data storage The toolkit stores persistent configuration in a platform-specific JSON settings file: - **macOS:** `~/Library/Application Support/macOS_IntuneManagement/Settings.json` - **Windows:** `%LOCALAPPDATA%\macOS_IntuneManagement\Settings.json` - **Linux:** `~/.local/share/macOS_IntuneManagement/Settings.json` Per-tenant settings are stored under a key matching the tenant GUID. On macOS, the client secret is stored in the macOS Keychain (service `IntuneMgmt-`, account `IntuneManagement`) instead of inside the JSON file. On non-macOS platforms the secret is written to the JSON file — treat that file as sensitive. Operational logs are written to `IntuneManagement.log` in the same data folder by default. ## Authentication Three authentication modes are supported, selected via `-AuthMode`: - `AppOnly` (default) — uses an Entra app registration with client secret or certificate. - `Browser` — interactive delegated auth using a public client. If `-AppId` is omitted, the Microsoft Graph PowerShell public client (`14d82eec-204b-4c2f-b7e8-296a70dab67e`) is used. - `DeviceCode` — delegated auth via device code; may be blocked by Conditional Access. First-time setup is performed by `Scripts/Initialize-IntuneAuth.ps1`, which: 1. Connects to Microsoft Graph with admin credentials. 2. Creates (or reuses) an Entra app registration named after the authenticated Entra user for audit traceability. 3. Ensures a broad set of Microsoft Graph application permissions are configured and grants admin consent. 4. Creates a client secret and stores it securely. The launcher caches tenant display names in `Settings.json` so the TUI can show friendly names. ## Main entry points | Script | Purpose | |---|---| | `intune` | Bash wrapper (macOS/Linux): launcher by default, or `intune