Remove-sqmMasterDbCustomObjects
Database HealthsqmSQLTool v1.9.110+ · Remove🔓 sysadmin, or ALTER ANY SCHEMA + CONTROL on the objects
Get-sqmMasterDbCustomObjects finds. Per instance it first re-detects the custom objects live (sys.objects, is_ms_shipped = 0, minus the configured MasterDbObjectWhitelist and anything matched by -ExcludeObject) rather than trusting a possibly stale object handed in through the pipeline. If -ObjectName is given, only those names (wildcards allowed) are considered; otherwise every non-whitelisted object found is a candidate. An instance with nothing left to remove is skipped entirely. Each remaining object is dropped with the statement matching its type (DROP TABLE / DROP VIEW / DROP PROCEDURE / DROP FUNCTION), each wrapped in its own try/catch so one failing object does not stop the rest. A CSV changelog is written per instance into -OutputPath and copied to the module's central path via Copy-sqmToCentralPath, the same way Repair-sqmDbOwnerRisk and Set-sqmDatabaseOwner do it. The whitelist that protects objects is configured module-wide with Set-sqmConfig -MasterDbObjectWhitelist; there is deliberately no per-call switch to bypass it.Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string[] | Optional | $env:COMPUTERNAME | One or more instances. Pipeline-capable by property name. |
| -SqlCredential | PSCredential | Optional | , | SQL or Windows credential. Without it: Windows authentication. |
| -ObjectName | string[] | Optional | every non-whitelisted object | Object name(s) to remove, wildcards allowed. Binds ObjectName from Get-sqmMasterDbCustomObjects through the pipeline. |
| -ExcludeObject | string[] | Optional | @() | Additional object names to leave alone even though they are not whitelisted (wildcards allowed). |
| -OutputPath | string | Optional | Get-sqmDefaultOutputPath\MasterDbCustomObjectsRemoval | Directory for the CSV changelog. |
| -ContinueOnError | switch | Switch | $false | Continue with the next instance on error. |
| -EnableException | switch | Switch | $false | Throw exceptions immediately instead of returning as errors. |
| -WhatIf / -Confirm | switch | Switch | ConfirmImpact = High | Drops are high-impact, so PowerShell prompts by default. -WhatIf lists what would be dropped without touching anything. |
Execution Flow
Examples
Dry run: show which objects would be dropped
Remove-sqmMasterDbCustomObjects -SqlInstance 'SQL01' -WhatIf
Clean up exactly what the report function found
Get-sqmMasterDbCustomObjects -SqlInstance 'SQL01' | Where-Object Status -eq 'Custom' | Remove-sqmMasterDbCustomObjects
Remove a single family of leftovers without prompting
Remove-sqmMasterDbCustomObjects -SqlInstance 'SQL01' -ObjectName 'usp_Test*' -Confirm:$false
Sweep several instances but keep one object
Remove-sqmMasterDbCustomObjects -SqlInstance 'SQL01','SQL02' -ExcludeObject 'usp_MyAdminTool' -ContinueOnError -WhatIf