r/PowerShell • • 17d ago

Script Sharing HybridScope – a WPF GUI that merges AD + Exchange on-prem + Microsoft 365 into one RVTools-style inventory (read-only, PS 5.1)

EDIT – v1.7.0 is out: HybridScope now also reads Microsoft Defender (Business Premium / Defender for Business): per user and PC, vulnerabilities, missing KBs, software to update and a prioritized fix list. Plus an MFA fix. Details in the comments / release notes.

I'm a sysadmin in a hybrid environment (Exchange 2019 + AD + Microsoft 365) and every time someone asked "how many mailboxes are still on-prem, how big are they, who has MFA, which licenses are wasted?" I ended up exporting three CSVs from three consoles and merging them in Excel by hand.

So I built HybridScope: one window, three sources, one merged view per user.

What it does

  • Pulls users from Active Directory, mailboxes from Exchange on-prem (Get-Mailbox, Get-MailboxStatistics, Get-RemoteMailbox) and licenses / sign-ins / OneDrive / MFA from Microsoft Graph
  • Tells you where each mailbox really lives (ON-PREM / 365 / NO MAILBOX) based on Exchange and Graph provisionedPlans, not on mailbox size
  • Real MFA status: registered methods, default method, legacy per-user state
  • RVTools-style tabs: Overview per OU, Users, Mailboxes on-prem / 365, OneDrive, MFA, Tenant licenses, an "Attention" list (on-prem mailboxes to migrate, licensed users without MFA, licenses on disabled accounts, inactive accounts)
  • 5 infrastructure modes with one click: Full Cloud / Full Hybrid / Hybrid (365 + AD) / On-Prem (Exchange + AD) / AD only
  • Export to formatted XLSX (ImportExcel) or CSV, all tabs or just the filtered current tab
  • -Auto switch for scheduled reports with certificate auth + history tracking
  • English / Italian UI

Some implementation details you might find interesting

  • Windows PowerShell 5.1, single .ps1, WPF built from XAML
  • All the heavy lifting runs in a persistent background runspace, so the UI never freezes; log lines come back through a ConcurrentQueue polled by a DispatcherTimer. There's a Stop button (BeginStop() on the running pipeline)
  • Only Microsoft.Graph.Authentication is needed: everything goes through Invoke-MgGraphRequest with manual paging, no giant SDK install
  • Exchange via implicit remoting (Import-PSSession, Kerberos), works from non-domain-joined PCs with explicit credentials
  • Read-only: it never writes anything to AD, Exchange or the tenant

Repo: https://github.com/Thonno/hybridscope (MIT)

HybridScope - Active Directory, Exchange and Microsoft 365 user report (PowerShell)

Screenshots are in the README (sensitive data blurred).

Full disclosure: I wrote it with a lot of help from an AI assistant and tested it on our own environment, so I'm sure there are edge cases I haven't hit yet. Feedback, issues and PRs are very welcome, especially from people with different setups (multiple Exchange orgs, big tenants, cloud-only).

37 Upvotes

9 comments sorted by

2

u/BlackV 17d ago

Quick look

  1. is there a specific reason you've made this ($global:HS_MethodNames) a global variable ?
  2. $m/$p/$r/etc (and any other single letter variables) clear as mud, is this the $p from your splat or the $p from your perms
  3. examples and help are lacking (imho)
  4. can someone for example, just run this and pull ONLY mfa status ?
  5. Can I run this without the GUI?

3

u/Suspicious_Rest4713 17d ago

Hi, first of all thanks a lot for taking the time to actually try HybridScope and write down your feedback, I really appreciate it. All your points were fair, so I’ve addressed them in 1.4.0:

  1. $global: No good reason, honestly. The same engine runs on the GUI thread and in a background runspace, and global was a quick way to share state between them. $script: scope works in both cases, so everything is script-scoped now and nothing is left behind in your session.
  2. Single-letter variables. Agreed, and you actually found a real bug with it: $M (the metric list) and $m (the loop variable) are the same variable in PowerShell, which broke the Overview sheet in the Excel export. Fixed, and every single-letter variable is now renamed to something readable.
  3. Help and examples. Agreed. There’s now full comment-based help with examples (Get-Help .\HybridScope.ps1 -Full) and a command-line section in the README.
  4. MFA only. Yes, now you can: .\HybridScope.ps1 -Only MFA. It only talks to Microsoft Graph, so no AD or Exchange. The same works for Licenses, Mailbox365, OneDrive and MailboxOnPrem. Data collection is now split into one function per source.
  5. Without the GUI. Yes:

    • -Auto gives the full report to Excel.
    • -PassThru gives you objects in the pipeline, e.g. .\HybridScope.ps1 -Only MFA -PassThru | Where-Object MFA_Registered -eq 'No' | Export-Csv no-mfa.csv.
    • If you’re already connected with Connect-MgGraph, it reuses that session.
    • AD and Exchange use the Windows account running the script and the settings in config.json.

Release: https://github.com/Thonno/hybridscope/releases/tag/v1.4.0

Thanks again, more feedback is always welcome!

1

u/BlackV 17d ago

Nice

1

u/Suspicious_Rest4713 12d ago

Hi all, 1.6.0 released.

What's new / Novità

Export: FULL, presets or custom columns

  • New Export content box next to the connection panels: choose what to export before Load data: FULL (every tab and column), a preset or Custom columns.
  • Built-in presets: Sign-ins and inactivity, Licenses, Mailbox migration, MFA security, Directory.
  • Custom: tick only the columns you need (e.g. just username, last AD logon, last Microsoft 365 sign-in). Save your own presets.
  • Options: one sheet per group, include OVERVIEW, enabled accounts only.

Dynamic load

  • Read only the data needed: with a preset or Custom, Load data reads only what those columns need, so it is much faster. A partial load is clearly flagged.

Command line

  • -ExportPreset <name> and -Columns <list>, e.g. .\HybridScope.ps1 -Auto -Columns Username,AD_LastLogon,M365_LastSignIn
  • New settings: AutoExportPreset, ExportFastLoad.

Icon

  • HybridScope now has its own icon: exe, main window, taskbar and dialogs.
  • tools\Build-Exe.ps1 sets the icon and the version in the exe properties. The exe contains the script: rebuild it after every update.

Full details: CHANGELOG

1

u/Suspicious_Rest4713 11d ago

Update – v1.7.0: security with Microsoft Defender

Bought Business Premium? HybridScope now reads Defender for Business / Defender for Endpoint and shows user → PC → what to fix:

  • Only users with a Defender license (Teams Essentials / Business Standard users stay out)
  • Per PC: risk, antivirus, alerts, vulnerabilities by severity, exploitable ones, missing KBs, software to update or out of support
  • A prioritized fix list (which KB / update fixes the most CVEs, on which PCs)
  • No Intune needed: PCs are linked to users from Defender logons or the Entra device owner
  • Browser sign-in through one app registration per tenant, still read-only

Also fixed: MFA % showing 0 for AD users (bug in 1.6.0).

Release: https://github.com/Thonno/hybridscope/releases/latest Setup guide: https://github.com/Thonno/hybridscope#microsoft-defender-security

Feedback welcome, especially from anyone with more PCs onboarded than my test tenant 🙂

1

u/Suspicious_Rest4713 6d ago

Update – v1.8.0-1.8.1

  • Double-click details on every tab: a number in OVERVIEW opens the list of the users behind it (group column or TOTAL; e.g. MFA per-user enforced, a license, inactive users, Defender), a license in TENANT_LICENSES lists who has it, a fix in SECURITY_FIXES lists the users of the PCs it fixes, and any other row (HISTORY, DEVICES_UNASSIGNED, ...) opens in a window with all its fields. The user lists have search, column filters, Copy and double-click for the user card. Saved reports (also made by someone else, in either language): the lists are recomputed when the report is opened, from its USERS and SECURITY tabs with the same rules and the report's date; a number stays without list only if the report lacks the columns it needs (e.g. a preset export)
  • Column filters in every grid: click the ▾ next to a column name to choose the values to show (search, select all, blanks), Excel-style; a blue ▼ marks the filtered columns, the filters add up with the search box and the row count follows them
  • OVERVIEW columns can no longer be sorted: a click on a header used to mix sections and rows in alphabetical order
  • Update check at startup: when the GUI opens, HybridScope asks GitHub for the latest release in the background and shows a message only if a newer version exists (offline / up to date: nothing). New setting CheckUpdatesAtStartup (default true); not used by -Auto
  • Fixed (since 1.5.0): opening a saved report where a group has the name of a tab in the other language (e.g. a group USERS in an Italian report) replaced the whole user list with that group: the USERS tab showed only its users. The report language is now detected from the sheet names
  • Double-click lists of saved reports now use the whole user list (they were empty for every group but the one with that name)

1

u/Belcia_Baeseler 16d ago

Respect for actually wiring up a persistent background runspace with a queue instead of letting the WPF window freeze for ten minutes. How are you matching the identities across the three sources, just anchoring on UPN or falling back to ImmutableId / GUIDs when UPNs dont match?

2

u/Suspicious_Rest4713 15d ago

1.5.0 released!

User card: double-click a user in any tab to see everything in one window: identity, AD, Microsoft 365, mailbox (on-prem and Exchange Online), OneDrive, MFA, sync data and notes. Copy puts the whole card on the clipboard
Groups and roles, loaded in the background: AD groups (direct, nested, primary) and Entra groups (Microsoft 365, security, distribution, dynamic; synced or cloud) and Entra roles, with a search box
SYNC tab: checks AD ↔ Entra ID the way Entra Connect / Cloud Sync link them (source anchor ms-DS-ConsistencyGuid / objectGUID vs onPremisesImmutableId) and lists what is broken or about to break:
last sync cycle, flagged when it is older than SyncStaleHours (default 3)
ImmutableId that no longer matches the AD anchor (account deleted and recreated)
synced accounts missing from AD, cloud accounts with a leftover ImmutableId
AD accounts that will soft-match or conflict with a cloud account at their first sync
provisioning errors reported by Entra, UPNs that fell back to onmicrosoft.com, duplicate anchors in AD
sync problems also appear in USERS (SyncIssues), ATTENTION and the overview; -Only Sync from the command line
Open a saved report: File > Open report (Ctrl+O) or drag & drop. XLSX, CSV export folder or single CSV, in either language. Browse, search, re-export and open user cards without connecting to anything
Menu bar: File (open, exports, reports folder) and Help (documentation with F1, Check for updates, report a problem, About)
Changed
AD and Entra accounts are paired by sync anchor first, names as a fallback
An AD account paired by name with a cloud account that is not synced from AD now shows Origin AD + cloud (not linked) instead of "AD synced": some overview counts may change
Fixed
Excel reports had no tables (no style, no header filters) with ImportExcel 7.8: table names like T1 read as a cell address and were skipped
Upgrading
Extract over your existing folder: config.jsonis not in the release and is kept; new settings get their default value
Connect 365 now also asks for GroupMember.Read.All and RoleManagement.Read.Directory (read-only, used only by the user card). Until an administrator consents, it connects with the previous permissions and the card shows AD groups only. -Auto needs no change
Check for updates contacts api.github.com, and only when you click it
Example: .\HybridScope.ps1 -Only Sync -PassThru | Where-Object Category -notlike '0 *' | Format-Table Category, Username, UPN, Details -Wrap

1

u/Suspicious_Rest4713 16d ago

Thanks! It's not UPN-first, actually. The main anchor is sAMAccountName, because it's the one value all three sources expose natively:

- AD → Entra: three tiers, and the first match wins:

  1. AD sAMAccountName = Entra onPremisesSamAccountName (Entra Connect writes this for synced users)
  2. AD UPN = Entra UPN
  3. sAMAccountName = the local part of the Entra UPN. It prefers the non-onmicrosoft.com UPN. This catches tenants where the UPN suffix was changed, or where users were soft-matched before sync.
    - AD → Exchange on-prem: by sAMAccountName from Get-Mailbox / Get-RemoteMailbox. Same forest, so there's no ambiguity.
    - Entra → usage reports (EXO mailbox size, OneDrive): by UPN, because that's the only key the reports give you. It also only works if concealed names are turned off.
    - MFA registration / per-user MFA state: by Entra object id.

Any Entra member that no AD user claims goes to a SOLO_CLOUD tab, so a missed match shows up there instead of disappearing. All lookups are prebuilt hashtables (case-insensitive in PowerShell), so the join is a single pass with no nested loops.

To be fair, it doesn't use onPremisesImmutableId / objectGUID (or mS-DS-ConsistencyGuid) yet. That's the more robust anchor, because it survives renames of both the sAM and the UPN. Tier 3 is the weak spot: a cloud-only "jsmith" could get paired with AD "jsmith". Adding ImmutableId as tier 0 is going on the roadmap. It would decode whichever value your Connect uses as the sourceAnchor.