Skip to content

Instantly share code, notes, and snippets.

@shaneis
Created May 25, 2018 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaneis/550c92eef4c1dca52460b60222c434b9 to your computer and use it in GitHub Desktop.
Save shaneis/550c92eef4c1dca52460b60222c434b9 to your computer and use it in GitHub Desktop.
$PatternMatch = '(?<ColumnName>\w+)\s*=\s*@(?<ParameterName>\w+)'
$FindStoredProcedureParameters = @{
SqlInstance = 'localhost\SQLServer2K16'
Database = 'master'
Pattern = $PatternMatch
IncludeSystemDatabases = $true
}
Find-DbaStoredProcedure @FindStoredProcedureParameters |
ForEach-Object -Process {
$ParentRow = $_
$_ | ForEach-Object StoredProcedureTextFound | Select-String -Pattern $PatternMatch -AllMatches | ForEach-Object Matches | ForEach-Object -Process {
[PSCustomObject]@{
ServerName = $ParentRow.SqlInstance
DatabaseName = $ParentRow.Database
SchemaName = $ParentRow.Schema
ProcedureName = $ParentRow.Name
TextFound = ($_.Groups | Where-Object Name -eq '0').Value
ColumnName = ($_.Groups | Where-Object Name -eq 'ColumnName').Value
ParameterName = ($_.Groups | Where-Object Name -eq 'ParameterName').Value
}
}
} | Where-Object { ($_.ColumnName -ne $_.ParameterName) } |
Select-Object -Property * -Unique
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment