← ENTRA TOOLBOX

Entra ID · READ-ONLY / LOCAL CSV · v1.0.0

Entra hybrid identity link coverage

Review the sync flag and immutable-ID presence for an approved user roster without exposing source anchor values.

Lab validation pending

Offline tests do not establish live directory behavior. Review the source and run first in a small authorized lab. Nothing runs in this browser.

What you’ll need

  • PowerShell 7 and Microsoft.Graph.Authentication
  • Existing access-controlled local Reports directory
  • Approved roster of 1–250 user GUIDs
  • Approved delegated User.Read.All in a Global, Process-scoped session in the supplied tenant.

Run locally

Replace fictional inputs with values approved for your environment. Use an access-controlled local folder for output.

# Fictional mylab.dev tenant and roster GUIDs
Connect-MgGraph -TenantId '11111111-1111-4111-8111-111111111111' -Scopes 'User.Read.All' -ContextScope Process -Environment Global
./Export-SwpEntraHybridLinkCoverage.ps1 -TenantId '11111111-1111-4111-8111-111111111111' -ObjectId '22222222-2222-4222-8222-222222222222' -CsvDirectory './Reports'

Read the results

FieldMeaning
ObjectIdApproved user GUID.
SyncStateCurrently synced, Not currently synced, or Not reported or invalid.
ImmutableIdReviewPresent, Blank or unreturned, or Unexpected type.
ReportAsOfUtcFrozen UTC run timestamp.
  • Presence does not prove that an anchor matches on-premises AD; no matching, synchronization health determination, or remediation.
  • Null or unreturned sync state is not proof of never having synced. Actual immutable-ID values are not exported.
  • Duplicate GUIDs are ignored; failure of any read stops the report without writing partial output. SDK handles transient retries.

Keep the output local and protected. A successful report does not prove complete directory visibility; do not use it by itself to change or remove accounts or groups.

Complete source

The display, clipboard copy, download and GitHub link refer to the same pinned source.

Export-SwpEntraHybridLinkCoverage.ps1POWERSHELL / READ ONLY
#requires -Version 7.0
<#
.SYNOPSIS
Review hybrid identity link metadata for a selected roster.
.DESCRIPTION
Reports onPremisesSyncEnabled and whether onPremisesImmutableId is populated, without exporting the identifier.
This is not a validation of the link, source anchor correctness, synchronization health, or a recommendation to change the anchor.
Runs one Graph GET per unique approved ID and writes a local CSV only after all reads succeed.
No login, consent, Graph writes, or tenant-wide discovery. SDK may retry transient failures.
.PARAMETER TenantId
The intended tenant GUID and a matching Global, delegated, Process-scoped Graph context.
.PARAMETER ObjectId
An explicit list of 1-250 approved user object GUIDs. No UPN lookups or wildcard filters. Duplicates are ignored.
.PARAMETER CsvDirectory
Existing protected filesystem directory. Default: current directory. The report will not replace an existing file.
.EXAMPLE
# Create ./Reports first and replace both fictional GUIDs.
Connect-MgGraph -TenantId '11111111-1111-4111-8111-111111111111' -Scopes 'User.Read.All' -ContextScope Process -Environment Global
./Export-SwpEntraHybridLinkCoverage.ps1 -TenantId '11111111-1111-4111-8111-111111111111' -ObjectId '22222222-2222-4222-8222-222222222222' -CsvDirectory './Reports'
.NOTES
Version 1.0.0 (2026-11-28), initial release. Lab validation pending.
Requires PowerShell 7 and Microsoft.Graph.Authentication, with approved delegated User.Read.All.
Read scope approval and the signed-in user's directory access still apply. Use a dedicated session.
Reports can identify directory objects by ID; protect local CSVs and never commit them.
ObjectId: approved user GUID. SyncState: Currently synced, Not currently synced, or Not reported/invalid.
ImmutableIdReview: Present, Blank or unreturned, or Unexpected type. No anchor values exported.
ReportAsOfUtc: frozen UTC run timestamp. Null does not establish that a user was never synced.
References: https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0
https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0
#>
[CmdletBinding()]
param(
    [Parameter(Mandatory)][guid]$TenantId,
    [Parameter(Mandatory)][ValidateCount(1,250)][guid[]]$ObjectId,
    [ValidateNotNullOrEmpty()][string]$CsvDirectory = '.'
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

function Get-SwpField {
    param($Object, [string]$Name)
    if ($null -eq $Object) { return $null }
    if ($Object -is [System.Collections.IDictionary]) { return ,($Object[$Name]) }
    $property = $Object.PSObject.Properties[$Name]
    if ($null -ne $property) { return ,($property.Value) }
    return $null
}

function Get-SwpVerifiedContext {
    param([guid]$ExpectedTenant, [string]$Scope)
    $current = Get-MgContext
    if ($null -eq $current -or [string](Get-SwpField $current 'TenantId') -ine $ExpectedTenant.ToString() -or
        (Get-SwpField $current 'AuthType') -ine 'Delegated' -or
        (Get-SwpField $current 'ContextScope') -ine 'Process' -or
        (Get-SwpField $current 'Environment') -ine 'Global' -or
        [string]::IsNullOrWhiteSpace([string](Get-SwpField $current 'Account'))) {
        throw 'Connect to the supplied tenant in a delegated, Global, Process-scoped Graph session first. No query was made with the unverified context.'
    }
    if ($Scope -notin (Get-SwpField $current 'Scopes')) {
        throw "The current context lacks the required delegated scope: $Scope. This report never grants or requests it."
    }
    return $current
}

function Protect-SwpCsvCell {
    param($Value)
    # Neutralize formula-like text without coercing real numeric report values.
    if ($Value -is [string] -and $Value -match '^[\s\p{Cc}\p{Cf}]*[=+@-]') { return "'" + $Value }
    return $Value
}

if ($TenantId -eq [guid]::Empty -or [guid]::Empty -in $ObjectId) {
    throw 'Tenant and object identifiers must be nonzero GUIDs.'
}
$directory = Get-Item -LiteralPath $CsvDirectory -ErrorAction Stop
if ($directory.PSProvider.Name -ne 'FileSystem' -or -not $directory.PSIsContainer) {
    throw 'CsvDirectory must be an existing filesystem directory.'
}
if (-not (Get-Command Get-MgContext -ErrorAction SilentlyContinue) -or
    -not (Get-Command Invoke-MgGraphRequest -ErrorAction SilentlyContinue)) {
    throw 'Microsoft.Graph.Authentication is required; review and install it separately. This report installs nothing.'
}

$requiredScope = 'User.Read.All'
$context = Get-SwpVerifiedContext $TenantId $requiredScope
$account = [string](Get-SwpField $context 'Account')
$clientId = [string](Get-SwpField $context 'ClientId')
$asOf = [DateTimeOffset]::UtcNow
$seen = [System.Collections.Generic.HashSet[guid]]::new()
$rows = [System.Collections.Generic.List[object]]::new()
foreach ($id in $ObjectId) {
    # One GET for each unique approved ID; no tenant enumeration or pagination.
    if (-not $seen.Add($id)) { continue }
    Write-Progress -Activity 'Entra hybrid link coverage' -Status "Read $($rows.Count) of $($ObjectId.Count) submitted entries"
    $verified = Get-SwpVerifiedContext $TenantId $requiredScope
    if ([string](Get-SwpField $verified 'Account') -ine $account -or
        [string](Get-SwpField $verified 'ClientId') -ine $clientId) {
        throw 'The Graph account or client changed. No partial report was written.'
    }
    $uri = 'https://graph.microsoft.com/v1.0/users/{0}?$select=id,onPremisesSyncEnabled,onPremisesImmutableId' -f $id.ToString()
    try {
        $record = Invoke-MgGraphRequest -Method GET -Uri $uri -OutputType PSObject -ErrorAction Stop
    }
    catch {
        throw "Graph could not read selected object $id. Verify the approved roster and access, and retry later if throttled. No partial report was written. Graph error: $($_.Exception.Message)"
    }
    if ([string](Get-SwpField $record 'id') -ine $id.ToString()) {
        throw "Graph did not return the expected ID for object $id. No partial report was written."
    }

    $data = [ordered]@{ ObjectId = $id.ToString() }
    # Keep the actual source anchor out of all output, even if malformed.
    $sync = Get-SwpField $record 'onPremisesSyncEnabled'
    $anchor = Get-SwpField $record 'onPremisesImmutableId'
    $data['SyncState'] = 'Not reported or invalid'
    if ($sync -is [bool]) {
        $data['SyncState'] = if ($sync) { 'Currently synced' } else { 'Not currently synced' }
    }
    $data['ImmutableIdReview'] = 'Blank or unreturned'
    if ($null -ne $anchor) {
        if ($anchor -isnot [string]) { $data['ImmutableIdReview'] = 'Unexpected type' }
        elseif (-not [string]::IsNullOrWhiteSpace($anchor)) { $data['ImmutableIdReview'] = 'Present' }
    }
    $data['ReportAsOfUtc'] = $asOf.ToString('o')
    foreach ($key in @($data.Keys)) { $data[$key] = Protect-SwpCsvCell $data[$key] }
    $rows.Add([pscustomobject]$data)
}
Write-Progress -Activity 'Entra preferred language readiness' -Completed

$stamp = $asOf.ToString('yyyyMMddTHHmmssfffZ', [Globalization.CultureInfo]::InvariantCulture)
$csvPath = Join-Path $directory.FullName "Entra_HybridLinkCoverage-${stamp}.csv"
$stream = $null
$writer = $null
$created = $false
try {
    # CreateNew atomically refuses an existing filename, even with concurrent runs.
    $stream = [IO.File]::Open($csvPath, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::None)
    $created = $true
    $writer = [IO.StreamWriter]::new($stream, [Text.UTF8Encoding]::new($false))
    foreach ($line in ($rows.ToArray() | ConvertTo-Csv -NoTypeInformation)) { $writer.WriteLine($line) }
    $writer.Dispose()
}
catch {
    try {
        if ($null -ne $writer) { $writer.Dispose() }
    }
    finally {
        if ($null -ne $stream) { $stream.Dispose() }
        if ($created) { [IO.File]::Delete($csvPath) }
    }
    throw
}
finally {
    if ($null -ne $stream) { $stream.Dispose() }
}
[pscustomobject]@{ Rows = $rows.Count; CsvPath = $csvPath }

Microsoft references