forked from ktaranov/sqlserver-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameterCaseCheck.ps1
More file actions
38 lines (32 loc) · 1.35 KB
/
ParameterCaseCheck.ps1
File metadata and controls
38 lines (32 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<#
.Synopsis
Search for any parameter that does not match the column name.
.OUTPUTS
Any parameter that does not match the column name
.NOTES
Original link: https://nocolumnname.blog/2018/05/25/finding-parameters-that-do-not-match-column-names/
Author: Shane O'Neill
#>
$PatternMatch = '(?<ColumnName>\w+)\s*=\s*@(?<ParameterName>\w+)'
$FindStoredProcedureParameters = @{
SqlInstance = 'localhost'
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