If no user is selected when trying to connect to Microsoft Graph, PowerShell crashes, while the Windows user selection dialog remains open:
> date
try {
Connect-MgGraph -ErrorAction stop -ContextScope Process -TenantId 'xxx' -ClientId 'yyy'
} catch {
Write-Warning 'Cannot Connect'
} finally {
'Esto sí se ejecuta!'
}
lunes, 20 de abril de 2026 12:32:47
ADVERTENCIA: Note: Sign in by Web Account Manager (WAM) is enabled by default on Windows. If using an embedded
terminal, the interactive browser window may be hidden behind other windows.
[proceso terminado con el código 1 (0x00000001)]
Ahora puede cerrar este terminal con Ctrl+D o presionar Entrar para reiniciar.
Windows PowerShell
Copyright (C) Microsoft Corporation. Todos los derechos reservados.
Instale la versión más reciente de PowerShell para obtener nuevas características y mejoras. https://aka.ms/PSWindows
PS C:\Users\41gu0026 > date
lunes, 20 de abril de 2026 12:40:39
Powershell crashed but Microsoft.AAD.BrokerPlugin process is still there
Get-Process Microsoft.AAD.BrokerPlugin -ErrorAction SilentlyContinue |? StartTime -gt (Get-Date 11:11:00) | select StartTime
StartTime
---------
20/04/2026 12:32:50
Can Connect-MgGraph have a -timeout parameter? Or better can this issue be fixed? Do you have any workaround?
On our real environment Windows User Selection Dialog is hide (a script launch a second script which launch connect-mgintune) and often we don't see the dialog, so first script can't know what happened.
Get-Module Microsoft.Graph.Authentication
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.35.1 Microsoft.Graph.Authentication
Describe the solution you'd like.
This works:
try {
Connect-MgGraph -ErrorAction stop -ContextScope Process -TenantId 'xxx' -ClientId 'yyy' -timeout 300
} catch {
Write-Warning 'Cannot Connect'
} finally {
'Esto sí se ejecuta!'
}
I will open an issue (this one feature request for timeout and the issue for fix Microsoft.AAD.BrokerPlugin management)
Additional context?
No response
If no user is selected when trying to connect to Microsoft Graph, PowerShell crashes, while the Windows user selection dialog remains open:
Powershell crashed but Microsoft.AAD.BrokerPlugin process is still there
Can Connect-MgGraph have a -timeout parameter? Or better can this issue be fixed? Do you have any workaround?
On our real environment Windows User Selection Dialog is hide (a script launch a second script which launch connect-mgintune) and often we don't see the dialog, so first script can't know what happened.
Describe the solution you'd like.
This works:
try {
Connect-MgGraph -ErrorAction stop -ContextScope Process -TenantId 'xxx' -ClientId 'yyy' -timeout 300
} catch {
Write-Warning 'Cannot Connect'
} finally {
'Esto sí se ejecuta!'
}
I will open an issue (this one feature request for timeout and the issue for fix Microsoft.AAD.BrokerPlugin management)
Additional context?
No response