-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhereParameterNameDoesNotMatchColumnName.ps1
More file actions
26 lines (23 loc) · 1.09 KB
/
WhereParameterNameDoesNotMatchColumnName.ps1
File metadata and controls
26 lines (23 loc) · 1.09 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
$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