← AZURE / ENTRA TOOLBOX

DELEGATED SIGN-IN / READ SCOPES

Connect to the intended Entra tenant

Start a delegated connection to an explicitly named tenant and verify the context before running a reader. Purpose selects the required read scopes; it does not grant your account broader administrative authority.

REVIEW CANDIDATE · LIVE TENANT VALIDATION PENDING

Verification is offline and mocked—not a successful connection to your tenant. Review the complete source, permission scope, and output handling before a small authorized test. Read-only does not mean risk-free.

RUNTIME
PowerShell 7; Microsoft.Graph.Authentication installed manually
CONNECTION
Explicit tenant · delegated identity · Global cloud · Process context
DELEGATED SCOPES
Users: User.Read.All · Groups: GroupMember.Read.All · Both: both scopes
DIRECTORY WRITES
None requested by these tools
OUTPUT
Verified Graph context in your PowerShell process
WEBSITE ACCESS
No tenant connection, credential form, or report upload

Before running anything

  1. Use a trusted PowerShell 7 environment. Obtain and review Microsoft.Graph.Authentication through your organization’s approved process. These scripts do not install modules, provision an app registration, or modify tenant settings.
  2. Choose the intended tenant ID from a trusted source. Confirm the operator account and the smallest purpose needed. Read the source locally; do not paste credentials or tokens into this website.
  3. Use only the delegated scopes listed above. Administrator consent is required for Application.Read.All, User.Read.All and GroupMember.Read.All; User.ReadBasic.All is subject to tenant consent policy. Existing approved consent may already cover the required scopes. A Microsoft sign-in or consent screen is not permission to bypass your organization’s approval process. These scripts do not grant admin consent or change consent policy; stop if the approved permissions are unavailable.
  4. Start with a selected test identity or group. Directory reads can expose confidential data and create query load. Review local transcript, terminal-history, and export policies before running.
# Inspect the local environment; this does not install anything.
$PSVersionTable.PSVersion
Get-Module Microsoft.Graph.Authentication -ListAvailable

Start deliberately, then inspect the result.

All IDs, accounts, and names below are fictional placeholders. Replace them with explicitly authorized values. Download the connection helper alongside the reader and use the same PowerShell process.

# FICTIONAL VALUES: replace the tenant GUID and expected operator account.
.\Connect-SwpEntra.ps1 -TenantId '11111111-1111-1111-1111-111111111111' -Purpose Users -ExpectedAccount 'operator@example.invalid'

# Inspect the resulting process context before reading directory data.
Get-MgContext | Select-Object TenantId, Account, AuthType, ContextScope, Scopes

# For group reporting instead, request the group-read purpose explicitly.
.\Connect-SwpEntra.ps1 -TenantId '11111111-1111-1111-1111-111111111111' -Purpose Groups -ExpectedAccount 'operator@example.invalid'

What the output does—and does not—establish.

  • Purpose defaults to Users. Choose Groups for the group report, or Both only when the intended work requires both sets of read permissions.
  • ExpectedAccount is optional in the script, but specifying it helps detect a sign-in with the wrong operator account. Verify the displayed account and tenant yourself as well.
  • UseDeviceCode is an explicit alternative sign-in flow, not a bypass for Conditional Access or your organization’s authentication requirements.
  • Only the Microsoft Graph Global cloud and a delegated Process-scoped session are supported by this preview. Sovereign clouds, application-only credentials, and managed identities are not implemented.

Complete source. One version.

The displayed source, clipboard copy, download, and GitHub link use the same published script version. Nothing runs when you view or copy this page.

Connect-SwpEntra.ps1POWERSHELL 7 / REVIEW PREVIEW
#requires -Version 7.0
<#
.SYNOPSIS
Connect explicitly to one Microsoft Entra tenant with delegated read scopes.
.DESCRIPTION
Requires Microsoft.Graph.Authentication, installed separately after review.
No module installation, credentials in files, profile edits, or directory writes.
An interactive delegated sign-in/consent is an intentional action when YOU run this file.
Existing wrong-tenant context is refused, not silently reused or disconnected.
Process scope limits SDK context persistence; it does not revoke browser sign-in sessions.
Scope/context checks do not prove every server-side permission or directory role.
.EXAMPLE
./Connect-SwpEntra.ps1 -TenantId '11111111-1111-4111-8111-111111111111' -Purpose Users
.NOTES
Global cloud only. Examples use fictional IDs. No live-tenant validation is claimed.
#>
[CmdletBinding()]
param(
    [Parameter(Mandatory)][guid]$TenantId,
    [ValidateSet('Users','Groups','Both')][string]$Purpose = 'Users',
    [string]$ExpectedAccount,
    [switch]$UseDeviceCode
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
function Get-SwpValue {
    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 Assert-SwpContext {
    param([string[]]$RequiredScopes)
    if (-not (Get-Command Get-MgContext -ErrorAction SilentlyContinue)) {
        throw 'Microsoft.Graph.Authentication is required. Review and install it separately; this script never installs modules.'
    }
    $context = Get-MgContext
    if ($null -eq $context) { throw 'No Graph context. First run Connect-SwpEntra.ps1 for the explicit tenant and purpose.' }
    if ([string](Get-SwpValue $context 'TenantId') -ine $TenantId.ToString()) { throw 'Wrong tenant context. No Graph request was made. Disconnect explicitly and reconnect to the intended tenant.' }
    if ([string](Get-SwpValue $context 'AuthType') -ine 'Delegated' -or [string]::IsNullOrWhiteSpace([string](Get-SwpValue $context 'Account'))) { throw 'A delegated signed-in account is required; application-only access is outside this script.' }
    if ([string](Get-SwpValue $context 'Environment') -ine 'Global') { throw 'Only the Global Microsoft Graph cloud is supported by this artifact.' }
    if ([string](Get-SwpValue $context 'ContextScope') -ine 'Process') { throw 'Use a Process-scoped Graph connection; persistent CurrentUser context is not accepted.' }
    $actualScopes = Get-SwpValue $context 'Scopes'
    foreach ($scope in $RequiredScopes) { if ($scope -notin $actualScopes) { throw "Missing delegated scope $scope. Reconnect explicitly for the required purpose; permissions are not broadened automatically." } }
    return $context
}

if ($TenantId -eq [guid]::Empty) { throw 'TenantId cannot be the empty GUID.' }
foreach ($name in @('Connect-MgGraph','Get-MgContext')) { if (-not (Get-Command $name -ErrorAction SilentlyContinue)) { throw 'Microsoft.Graph.Authentication is required; install it separately after review.' } }
$existing = Get-MgContext
if ($null -ne $existing -and [string](Get-SwpValue $existing 'TenantId') -ine $TenantId.ToString()) { throw 'Existing context is for another tenant. Run Disconnect-MgGraph explicitly, then retry with the intended tenant.' }
$required = switch ($Purpose) { 'Users' { @('User.Read.All') }; 'Groups' { @('GroupMember.Read.All') }; 'Both' { @('User.Read.All','GroupMember.Read.All') } }
$connect = @{ TenantId = $TenantId.ToString(); Scopes = $required; ContextScope = 'Process'; Environment = 'Global'; NoWelcome = $true; ErrorAction = 'Stop' }
if ($UseDeviceCode) { $connect.UseDeviceCode = $true }
$null = Connect-MgGraph @connect
$context = Assert-SwpContext $required
$account = [string](Get-SwpValue $context 'Account')
if ($ExpectedAccount -and $account -ine $ExpectedAccount) { throw 'The signed-in account does not match ExpectedAccount. No directory query was made; disconnect and choose the intended account.' }
[pscustomobject]@{
    TenantId = $TenantId.ToString(); Account = $account; AuthType = 'Delegated'; ContextScope = 'Process'; Environment = 'Global'
    RequestedReadScopes = @($required); ContextScopes = Get-SwpValue $context 'Scopes'
    Verification = 'Context matches requested tenant, delegated account, cloud and scope requirements. Verify the displayed account; this is not an effective-access audit.'
}

Local output is still sensitive.

These tools do not send results to ShellWePlay. When a reader’s CsvDirectory option is used, the export is written on the machine running PowerShell—not in the browser. Choose an existing access-controlled folder. Keep tenant IDs, account identifiers, memberships, and ownership information out of public shares and tickets unless authorized.

Do not treat CSV as harmless text: review the source’s export handling and your spreadsheet tooling. A successfully written file is not proof of complete directory visibility. Keep the coverage limitations with the result.

End your dedicated session deliberately.

When you are finished with the Graph session you opened for this work, disconnect it explicitly. Do not disconnect another workflow’s shared session without checking. Closing this website does not disconnect PowerShell, and a Process-scoped context does not sign you out of your browser or revoke all sign-in sessions.

# Run only when finished with your own dedicated Graph session.
Disconnect-MgGraph

Microsoft references