Commands / Get-sqmLinkedServerUsage
Get-sqmLinkedServerUsage
Database sqmSQLTool v1.8.2+ · Query
Analyzes which database objects (procedures, functions, views, triggers) and optionally SQL Agent job steps reference a linked server. Searches object definitions in sys.sql_modules and job definitions via msdb.dbo.sysjobsteps.

Useful for impact analysis before removing or renaming linked servers.

Execution Flow

START Get-DbaDatabase (exclude system) Convert -LinkedServer wildcard to SQL LIKE pattern foreach $db in $dbList Query sys.sql_modules (JOIN sys.objects) WHERE definition LIKE %$linkedServerPattern% For each row: add [PSCustomObject] to results catch per-DB error: log warning (continue) SqlInstance, Database, Schema, ObjectName, ObjectType, LinkedServer -IncludeJobs set? YES Query msdb job steps Add to results NO Return [PSCustomObject[]] linked server usage results

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestringOptional$env:COMPUTERNAMETarget SQL Server instance.
-SqlCredentialPSCredentialOptionalCredentials for the connection.
-LinkedServerstringOptional* = allLinked server name or wildcard pattern.
-IncludeJobsswitchOptional$falseAlso search SQL Agent job steps.
-EnableExceptionswitchOptional$falseRe-throw exceptions instead of warning.

Examples

Find all objects using a specific linked server
Get-sqmLinkedServerUsage -SqlInstance "SQL01" -LinkedServer "PROD_SRV"
Find all linked server usage including jobs
Get-sqmLinkedServerUsage -SqlInstance "SQL01" -IncludeJobs