Test-sqmLoginGroupAccess
SecuritysqmSQLTool v1.9.119+ · Test🔓 VIEW ANY DEFINITION + AD read access
CONNECT SQL), or a usable login does exist for one of their groups but has no matching database user in the target database, because no CREATE USER ... FOR LOGIN was ever run there. This function answers both questions in one pass: it resolves every AD group the user belongs to, direct and nested, via Get-sqmADMemberGroups; checks sys.server_principals on -SqlInstance for a Windows-group login matching each of those groups and whether it is enabled and not denied; and for every login found this way checks each accessible database's sys.database_principals by SID, not by name (names can differ) for a mapped user and its role memberships. Results are saved as TXT and HTML report in -OutputPath, and the flat array of per-user result objects, each with a nested per-group Detail[], is still returned. A reachable domain controller is required, so this is not usable in a workgroup-only lab.Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -Identity | string[] | Required | , | The AD user having trouble logging in. SamAccountName, UPN or DistinguishedName. Pipeline-capable. |
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Instance to check logins and database access on. |
| -SqlCredential | PSCredential | Optional | , | SQL or Windows credential. Without it: Windows authentication. |
| -Domain | string | Optional | auto-detected | AD domain. Auto-detected when not specified (see Get-sqmADMemberGroups). |
| -Depth | int (0-10) | Optional | 2 | Maximum AD group nesting depth to resolve, passed through to Get-sqmADMemberGroups. |
| -Database | string[] | Optional | all accessible databases | Restrict the database-level check to these databases (wildcards allowed). |
| -ExcludeDatabase | string[] | Optional | @() | Databases to skip during the database-level check (wildcards allowed). |
| -ExcludeSystemDatabases | switch | Switch | $false | Skip master, model, msdb and tempdb during the database-level check. |
| -OutputPath | string | Optional | Get-sqmDefaultOutputPath\LoginGroupAccess | Output directory for the TXT/HTML report files. |
| -NoOpen | switch | Switch | $false | Do not automatically open the generated report. |
| -ContinueOnError | switch | Switch | $false | Continue with the next identity on error instead of throwing. |
| -EnableException | switch | Switch | $false | Throw exceptions immediately instead of returning as errors. |
Execution Flow
Examples
Why can this user not log in?
Test-sqmLoginGroupAccess -Identity "john.doe" -SqlInstance "SQL01"
Narrow the check to one database
Test-sqmLoginGroupAccess -Identity "john.doe" -SqlInstance "SQL01" -Database "AdventureWorks"
Several users at once, user databases only
"john.doe","jane.roe" | Test-sqmLoginGroupAccess -SqlInstance "SQL01" -ExcludeSystemDatabases -ContinueOnError
Resolve deeper group nesting
Test-sqmLoginGroupAccess -Identity "john.doe" -SqlInstance "SQL01" -Depth 5