Skip to content

Pivoted view, duplicate detection, local styling, CSV and Json exports.#13

Draft
joelst wants to merge 15 commits intodougsbaker:mainfrom
joelst:main
Draft

Pivoted view, duplicate detection, local styling, CSV and Json exports.#13
joelst wants to merge 15 commits intodougsbaker:mainfrom
joelst:main

Conversation

@joelst
Copy link
Copy Markdown

@joelst joelst commented Aug 15, 2025

This pull request introduces improvements to the CA Export toolset with new functionality and better error handling.

New Features & Enhancements

New Parameters for Export-CAPolicywithRecs.ps1

  • Added NoBrowser switch to generate HTML without auto-launching browser
  • Added OutputPath parameter for custom output directory specification
  • Added CsvPivot switch for wide-format CSV suitable for Excel/BI tools
  • Added CsvColumns parameter for custom column selection and ordering
  • Added NoRecommendations switch to skip analysis for faster exports in large tenants

Improved Module Management

  • New Initialize-GraphModule function automatically installs/imports required Microsoft Graph modules
  • Enhanced Graph connection handling with scope validation
  • Better error handling and user guidance for missing dependencies

Enhanced Data Structure

  • Implemented ordered PSCustomObjects using [PSCustomObject][ordered]@{} for consistent property ordering
  • Improved entity resolution for users, groups, roles, and applications
  • Enhanced GUID detection and replacement in free-text fields

Export Control

  • Intelligent export behavior: no parameters = HTML + JSON + CSV, specific parameters = only those formats
  • Pivoted CSV remains opt-in for specialized use cases
  • Consistent timestamped filename patterns distinguishing script types

Data View

  • Export-CAPolicywithRecs.ps1 has each policy on a separate row instead of in columns.
  • Export-CAPolicy.ps1 has the original data format.

Technical Improvements

Code Quality & Maintainability

  • Complete refactor of helper functions with PowerShell best practices
  • Added comprehensive parameter validation including GUID pattern validation
  • Improved error handling with Invoke-SafeGet wrapper for graceful failures
  • Enhanced function documentation with detailed examples

Performance & Reliability

  • Better Graph API connection management with context validation
  • Improved entity resolution with bulk operations where possible
  • Enhanced role resolution supporting both active directory roles and role definitions

Repository Organization

File Management

  • Updated .gitignore to exclude *.csv files
  • Reorganized screenshot assets to images/ directory
  • Updated documentation to reflect correct filename patterns:
    • Full script: CAExportRecs_<TenantName>_YYYYMMDD_HHMMSS.*
    • Lightweight script: CAExport_<TenantName>_YYYYMMDD_HHMMSS.*

Documentation Updates

  • Added comprehensive parameter documentation with usage examples
  • Enhanced license section with friendly community message
  • Updated screenshots to reflect current UI

Version Information

  • Version: 3.1.1
  • Compatibility: PowerShell 7+ recommended, backward compatible
  • Dependencies: Microsoft Graph PowerShell modules (auto-installed)

@joelst
Copy link
Copy Markdown
Author

joelst commented Aug 15, 2025

I really liked your scripts. I wanted a couple of additional features, like exporting the data to a CSV so that I can do some work on the data in Excel. I started making a few tweaks and then ended up adding more and more tweaks.

You do not have to accept the changes. I am just sharing my changes to allow others to use them.

You may not like that I pivoted the view on the Export-CAPolicywithRecs.ps1 script to show each policy in a row instead of a column. The other script I left in the existing format.

  • Naming standardization suggestions.
  • Adding in more baseline recommendations.
  • Adjusting the policy layout to better display how the policy works.

joelst added 12 commits August 21, 2025 20:12
… export improvements

- Add -RawInputFile offline mode: accepts prior *_raw.json, skips Graph calls & module init, rehydrates policies for HTML/CSV/JSON/recommendations.
- Bump script version to 3.3 and document offline behavior in README.
- Add parameter hardening: PolicyID GUID validation, OutputPath validation and default, placeholder param for removed -Quiet to avoid positional shift.
- Improve Graph module initialization & import: prefer TLS1.2, handle PSGallery trust, install modules without -SkipPublisherCheck, better error handling and verbose messages.
- Harden Connect-GraphContext and Invoke-SafeGet with clearer try/catch structure and required-scope check.
- Add a suite of helper functions:
  - Test-PolicyTargetsAdminRoles, Initialize-AuthStrengthCache, Get-AssignedAuthStrengthObject,
    Test-IsPhishResistantStrength, Test-PolicyRequiresMfaForAdmins, Test-PolicyRequiresPhishResistantMfaForAdmins
  - Test-OverlapIncludeExclude, New-TokenSet, Protect-RecNote, Get-NormalizedPolicyHash
  - Consolidated CA check functions (Test-CA00..Test-CA12) for testability.
- Duplicate detection: extract normalization & hashing into Get-NormalizedPolicyHash and use for IsDuplicate/ContentHash.
- Name / Block mismatch analysis: flag policies whose name implies allow/block that contradicts grant control; surface in HTML with visual indicators.
- Recommendations inlined (removed external PSD1): sanitized notes, enriched CA-05 phish-resistant logic now inspects Authentication Strength AllowedCombinations.
- Lookup/enrichment improvements: resilient role resolution (directory roles, role definitions, static template fallback), improved user/group/app/location/TOU enrichment and offline skips.
- HTML UI enhancements:
  - Overlap legend chip + row highlighting for include/exclude intersections; per-policy overlap detail in recommendation cards.
  - Lazy JSON loading for per-policy Mutated/Original JSON to reduce initial payload; client-side RawPolicyDataIndex for on-demand original snapshots.
  - Accessibility and styling tweaks: improved header, policy-link controls, name-mismatch styles, legend chips, buttons and ARIA live announcements.
  - Sanitize recommendation HTML via Protect-RecNote (strip scripts/styles/handlers) while preserving curated markup.
- Export robustness:
  - JSON/RAW write error handling improved.
  - CSV selection logic validates requested columns and warns on unknown columns.
  - Pivot CSV and CSV export flow clarified and error-handled.
- Tests: add Pester tests (tests/Export-CAPolicyWithRecs.Tests.ps1) covering normalized hashing, phish-resistant checks and representative CA checks.
- README: fix typos, document new features (offline mode, phish-resistant details, overlap/UI notes), and update version history.

Misc: many whitespace/formatting cleanups and defensive null/empty checks across functions to improve readability and reliability.
…fix CA checks and recommendation text

- Render multi-row table header with grouped category spans and per-column classes for consistent color palette and improved readability
- Adjust sticky positions to account for two-row header stack and move header colors into group-specific CSS classes
- Update header generation logic to map columns to group classes and include sanity comment
- Fix Test-CA07 condition (one-line formatting) and correct property casing for IncludeGuestsOrExternalUsers
- Rename CA-06 recommendation title for clarity and correct "Passsword" -> "Password" typo in CA-09 link text
…policies; adjust HTML/CSS

- Update CA-06 and CA-07 recommendation text for clearer messaging.
- Differentiate recommendation pass/fail rendering by policy state (enabledForReportingButNotEnforced vs enabled), adding semantic classes (.success-report, .success-enabled, .warning-report, .warning-enabled) and adjusting status logic.
- Tweak HTML/CSS: reduce various font sizes, adjust responsive breakpoints, update summary table and back-to-top sizing, and minor layout/style refinements for improved readability.
…abled' state to distinct success/warning classes and add .policy-item.success-disabled/.policy-item.warning-disabled styles
…/IncludeGroups/IncludeRoles and GuestOrExternalUserTypes to robustly handle null, empty or whitespace values
…den CA07 checks

- Remove unused placeholder parameter and obsolete $script:QuietPreference variable.
- Harden Test-CA07 user checks: simplify null/empty checks for IncludeUsers/IncludeGroups/IncludeRoles and treat IncludeGuestsOrExternalUsers.GuestOrExternalUserTypes as null when absent.
- Consolidate and compact ID collection loops for users/groups/roles/apps/locations/termsOfUse; use Test-IsGuid for GUID-only collections.
- Build RawPolicyIndex directly from $CAPolicy (remove shallow clone) and produce rawIndexJson from $CAPolicy for the HTML lazy-load payload.
- Remove nested New-TokenSet definition from the HTML generation block and perform minor formatting/clarity cleanups.
…t-Process on Windows/PS<=5, open on macOS, xdg-open on Linux) and emit info fallback when unsupported
…simplify UI/JS

- Clean up cmdlet parameter help text and JSON description.
- Tighten helper function signatures/formatting and harden CA checks (null/whitespace handling).
- Replace fixed recommended-name id with randomized 3-digit token; minor naming tweaks.
- Remove content-based duplicate normalization/hash detection and name-mismatch analysis (cleanup of related fields/columns).
- Simplify CAExport shape: remove raw ID columns, fold/resurface assignment columns, normalize column names.
- Improve HTML report UI/CSS:
  - Add status filter control and accessible live-region feedback.
  - Replace ID-column / overlap / duplicate toggles with streamlined layout and assignment truncation/expand.
  - Add compact status labels/pills and grant/block visuals.
  - Various CSS/layout refinements for sticky headers and responsive tables.
- Simplify client JS: remove value-match/column select/overlap features, implement lazy JSON handling and assignment expand, persist status filter.
- Refactor module/Graph init and error handling messages; minor NuGet/PSGallery install messages.
- Adjust CSV/pivot defaults and CSV export column selection logic; minor JSON/CSV write error handling improvements.
@joelst joelst marked this pull request as draft October 23, 2025 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant