· Uwe Janke
Commands / Get-sqmMasterDbCustomObjects

Get-sqmMasterDbCustomObjects

Database HealthsqmSQLTool v1.9.110+ · Get🔓 VIEW ANY DEFINITION in master
Users occasionally create objects directly in master by accident: the wrong database selected in SSMS, a script run without a USE statement, ad-hoc troubleshooting left behind. Unlike a user database, master has no natural owner for "this should not be here", so anything not shipped by Microsoft and not part of the standard maintenance tooling is a cleanup candidate. Reads sys.objects in master for tables, views, procedures and functions (U/V/P/PC/FN/IF/TF/FS/FT), excluding genuine Microsoft objects (is_ms_shipped = 1) and anything matched by the MasterDbObjectWhitelist module configuration (wildcards allowed, see Get-sqmConfig -Key 'MasterDbObjectWhitelist'). The default whitelist covers the standard maintenance-script family: sp_Blitz*, sp_WhoIsActive, Ola Hallengren's CommandExecute / CommandLog / DatabaseBackup / DatabaseIntegrityCheck / IndexOptimize, and sp_BackRestRemain. Output is one row per found object plus one OK row per instance with nothing found, along with TXT/CSV/HTML report files. This function only reports - use Remove-sqmMasterDbCustomObjects to drop what it finds.

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestring[]Optional$env:COMPUTERNAMEOne or more instances. Pipeline-capable.
-SqlCredentialPSCredentialOptional, SQL or Windows credential. Without it: Windows authentication.
-ExcludeObjectstring[]Optional@()Additional object names to exclude for this call only (wildcards allowed), on top of the configured whitelist. For a one-off tool you know is legitimate, without changing the persisted configuration.
-OutputPathstringOptionalGet-sqmDefaultOutputPath\MasterDbCustomObjectsOutput directory for the HTML/TXT/CSV report.
-ContinueOnErrorswitchSwitch$falseContinue with the next instance on error.
-EnableExceptionswitchSwitch$falseThrow exceptions immediately instead of returning as errors.
-NoOpenswitchSwitch$falseDo not automatically open the generated report.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES Read the whitelist from the module configuration Get-sqmConfig -Key 'MasterDbObjectWhitelist' + any -ExcludeObject for this call Query sys.objects in master Types U/V/P/PC/FN/IF/TF/FS/FT · is_ms_shipped = 0 Microsoft-shipped objects are never candidates Object matched by the whitelist? YES Expected tooling - not reported sp_Blitz*, sp_WhoIsActive, Ola Hallengren, sp_BackRestRemain NO Status = Custom One row per object: name, type, schema, create/modify date Write TXT + CSV + HTML report One OK row per instance where nothing was found · opened unless -NoOpen Return [PSCustomObject] per object SqlInstance · Database · SchemaName · ObjectName · ObjectType · Status DONE

Examples

Check the local instance
Get-sqmMasterDbCustomObjects
Several instances, with a one-off exception
Get-sqmMasterDbCustomObjects -SqlInstance 'SQL01','SQL02' -ExcludeObject 'usp_MyAdminTool'
Only the actual findings
Get-sqmMasterDbCustomObjects -SqlInstance 'SQL01' | Where-Object Status -eq 'Custom'
Feed the findings straight into the removal function (dry run first)
Get-sqmMasterDbCustomObjects -SqlInstance 'SQL01' | Where-Object Status -eq 'Custom' | Remove-sqmMasterDbCustomObjects -WhatIf
Add a legitimate tool to the whitelist permanently
Set-sqmConfig -MasterDbObjectWhitelist ((Get-sqmConfig -Key 'MasterDbObjectWhitelist') + 'usp_MyAdminTool')