Test-sqmDiscoveryAccess
Inventory
sqmSQLTool v1.9.135+ · Test
✓ -WhatIf supported
What is reported per instance: does the login exist, is it enabled, is CONNECT SQL denied; is it a member of the expected server role; which effective server permissions it really has (direct grants, every server role it is a member of, nested, and
public, with DENY winning); whether VIEW ANY DATABASE is still granted to public; whether the account is over-privileged (sysadmin is never required for discovery).
DiscoveryLevel is what the collecting tool can actually see:
None or ServerOnly (instance data only, which needs no SQL login), Databases (names, state, recovery model, collation, owner), DatabaseDetails (additionally sizes and file paths, needs VIEW ANY DEFINITION) and Full (additionally port, CPU/RAM, cluster and AG topology, needs VIEW SERVER STATE).
The hardening trap. Without
VIEW ANY DATABASE SQL Server reports no error: the account simply sees only master and tempdb. That happens when a hardening baseline revoked the permission from public. The function reads read-only and changes nothing. If the account gets access through an AD group login, it is reported as missing; use Test-sqmLoginGroupAccess for that.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string[] | Optional | $env:COMPUTERNAME | One or more instances. Pipeline-capable, a server list can be piped in. |
| -LoginName | string | Required | , | The service account to verify, for example CORP\SVC-SNOW-DISCO. Windows login, Windows group login or SQL login. |
| -ServerRole | string | Optional | , | Expected server role membership. Without it the role check is skipped. |
| -RequiredLevel | string | Optional | Databases | ServerOnly, Databases, DatabaseDetails or Full. Anything below it fails the instance. |
| -SqlCredential | PSCredential | Optional | , | The DBA's own connection, not the account being checked. |
| -OutputPath | string | Optional | <OutputPath config>\DiscoveryAccess | Report directory. |
| -NoOpen | switch | Switch | $false | Do not open the report. |
| -ContinueOnError | switch | Switch | $false | Continue with the next instance on error. |
| -EnableException | switch | Switch | $false | Throw exceptions immediately. |
| -WhatIf / -Confirm | switch | Optional | , | Skips the check and marks the instances WhatIf. |
Execution Flow
Return value
One object per instance with Reachable, LoginExists, IsDisabled, DenyConnectSql, IsSysadmin, ServerRoles, InServerRole, PublicViewAnyDb, ViewAnyDatabase, ViewAnyDefinition, ViewServerState, GrantedPermissions, DiscoveryLevel, RequiredLevel, MeetsRequirement, Findings and Status.
| Status | Meaning |
|---|---|
OK | The required level is reached and there are no findings. |
Warnung | The required level is reached, but there are findings (for example sysadmin, a missing optional permission). |
Fehler | The account stays below the required level. |
Error | The instance could not be checked (connection or query failed). |
WhatIf | -WhatIf: nothing was checked. |
The status words Warnung and Fehler are the literal values the function returns. On SQL Server 2022 and later the server reports VIEW SERVER PERFORMANCE STATE instead of VIEW SERVER STATE.
Examples
One instance against the default requirement (server plus database listing)
Test-sqmDiscoveryAccess -SqlInstance SQL01 -LoginName "CORP\SVC-SNOW-DISCO"
Sweep a server list, also checking the role
Get-Content .\sqlserver.txt | Test-sqmDiscoveryAccess -LoginName "CORP\SVC-SNOW-DISCO" `
-ServerRole "SQL_Inventory_RO_Basic" -NoOpenRequire the DMVs as well (port, CPU/RAM, cluster and AG topology)
Test-sqmDiscoveryAccess -SqlInstance SQL01, SQL02 -LoginName "CORP\SVC-SCOM" -RequiredLevel Full
Only the instances that need attention
Test-sqmDiscoveryAccess -SqlInstance SQL01, SQL02 -LoginName "CORP\SVC-SNOW-DISCO" -NoOpen |
Where-Object Status -ne "OK" | Format-List SqlInstance, DiscoveryLevel, Findings