Execution Flow
Synopsis
Supports pipeline input for -SqlInstance and iterates all specified instances in the process block. On each instance, a single Invoke-DbaQuery retrieves all logins from sys.server_principals. Results are filtered client-side by -ExcludeSystemLogins, -DefaultDatabase, and -DefaultLanguage. An optional CSV + HTML export is written in the end block.
Requires dbatools. The SQL query excludes double-hash accounts (
##%##) server-side. -ExcludeSystemLogins additionally removes NT SERVICE\*, NT AUTHORITY\*, and ##MS_*## patterns client-side.Syntax
Get-sqmLoginSettings [-SqlInstance <String[]>] # pipeline; default $env:COMPUTERNAME [-SqlCredential <PSCredential>] [-LoginType <All|SQL|Windows>] # default All [-ExcludeSystemLogins] [-DefaultDatabase <String>] [-DefaultLanguage <String>] [-OutputPath <String>] [-ContinueOnError] [-EnableException] [-NoOpen]
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| -SqlInstance | String[] | $env:COMPUTERNAME | One or more SQL Server instances. Accepts pipeline input. |
| -SqlCredential | PSCredential | — | Optional SQL connection credential. |
| -LoginType | String | All | All = SQL + Windows users + Windows groups; SQL = type S only; Windows = types U and G only. |
| -ExcludeSystemLogins | Switch | false | Skip NT SERVICE\*, NT AUTHORITY\*, and ##MS_*## logins. |
| -DefaultDatabase | String | — | Filter: only return logins with this default database. |
| -DefaultLanguage | String | — | Filter: only return logins with this default language (e.g. us_english). |
| -OutputPath | String | — | Directory to write CSV and HTML report. No export when omitted. |
| -ContinueOnError | Switch | false | Continue to next instance on error instead of throwing. |
| -EnableException | Switch | false | Throw terminating exceptions immediately. |
| -NoOpen | Switch | false | Suppress automatic opening of the generated HTML report. |
Return Value
| Property | Description |
|---|---|
| SqlInstance | Source instance name. |
| LoginName | Login name from sys.server_principals.name. |
| LoginType | SQL_LOGIN, WINDOWS_LOGIN, or WINDOWS_GROUP. |
| DefaultDatabase | Default database for the login. |
| DefaultLanguage | Default language for the login. |
| IsDisabled | $true when the login is disabled. |
| CreateDate | Login creation timestamp. |
| ModifyDate | Login last-modified timestamp. |
Examples
# All logins on local instance Get-sqmLoginSettings # Windows logins only, exclude system accounts Get-sqmLoginSettings -SqlInstance "SQL01" -LoginType Windows -ExcludeSystemLogins # Find all logins pointing at master with German language Get-sqmLoginSettings -SqlInstance "SQL01" -DefaultDatabase "master" -DefaultLanguage "Deutsch" # Multi-instance export Get-sqmLoginSettings -SqlInstance "SQL01","SQL02" -OutputPath "C:\Reports" -ContinueOnError