Skip to content

Commit b5881ce

Browse files
committed
Update some powershell scripts info
1 parent 3048242 commit b5881ce

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

PowerShell/Clone-SQLLogin.ps1

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
11
<#
22
.Synopsis
3-
Clone a SQL Server Login based on another exsiting login.
3+
Clone a SQL Server Login based on another exsiting login.
4+
45
.DESCRIPTION
5-
Clone a SQL Server Login based on another exsiting login on one or multiple servers and the process can generate a script for auditing purpose.
6+
Clone a SQL Server Login based on another exsiting login on one or multiple servers and the process can generate a script for auditing purpose.
7+
68
.EXAMPLE
7-
The following command scripts out the permissions of login account [John] and generates the script at "c:\temp\clone.sql"
8-
Notice, parameters [OldLogin] and [NewLogin] uses the same value of "John"
9-
Clone-SQLLogin -Server Server1, Server2 -OldLogin John -NewLogin John -FilePath "c:\temp\clone.sql"
9+
The following command scripts out the permissions of login account [John] and generates the script at "c:\temp\clone.sql"
10+
Notice, parameters [OldLogin] and [NewLogin] uses the same value of "John"
11+
Clone-SQLLogin -Server Server1, Server2 -OldLogin John -NewLogin John -FilePath "c:\temp\clone.sql"
1012
1113
.EXAMPLE
1214
The following command exports a script that can be used to clone login account [John] for new login account [David], and the script is created at "c:\temp\clone.sql"
1315
also the -Execute parameter means the new account "David" will be created
1416
Clone-SQLLogin -Server Server1, Server2 -OldLogin John -NewLogin David -NewPassword 'P@$$W0rd' -FilePath "c:\temp\clone.sql" -Execute;
15-
17+
1618
.Parameter ServerInstance
17-
ServerInstance is of string array datat ype, and can accept a string of sql instance names, spearated by comma. (mandatory)
18-
19+
ServerInstance is of string array datat ype, and can accept a string of sql instance names, spearated by comma. (mandatory)
20+
1921
.Parameter OldLogin
20-
The login account is the source where all the permissions will be scripted out and to be used for the NewLogin account (mandatory)
21-
22+
The login account is the source where all the permissions will be scripted out and to be used for the NewLogin account (mandatory)
23+
2224
.Parameter NewLogin
23-
The login account is the target account that we want to clone (mandatory)
24-
25+
The login account is the target account that we want to clone (mandatory)
26+
2527
.Parameter NewPassword
2628
The password for the new login account if we want to create the login, default to empty string "" (optional)
27-
29+
2830
.Parameter FilePath
29-
The full path name for the generated sql script (optional)
31+
The full path name for the generated sql script (optional)
3032
3133
.Parameter Execute
32-
This is a swich parameter, if present, it means we need to create the NewLogin account.
33-
34+
This is a swich parameter, if present, it means we need to create the NewLogin account.
35+
3436
.OUTPUTS
35-
none
37+
none
38+
3639
.NOTES
37-
A few service broker related permissions are not covered in this version 1.
38-
Original link: https://www.mssqltips.com/sqlservertip/4572/cloning-a-sql-server-login-with-all-permissions-using-powershell/
39-
Author: Jeffrey Yao
40+
A few service broker related permissions are not covered in this version 1.
41+
Original link: https://www.mssqltips.com/sqlservertip/4572/cloning-a-sql-server-login-with-all-permissions-using-powershell/
42+
Author: Jeffrey Yao
4043
#>
4144
#requires -version 3.0
4245
add-type -assembly "Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"; #if Version-11.xx means sql server 2012

PowerShell/ParameterCaseCheck.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
$PatternMatch = '(?<ColumnName>\w+)\s*=\s*@(?<ParameterName>\w+)'
1+
<#
2+
.Synopsis
3+
Search for any parameter that does not match the column name.
4+
5+
.OUTPUTS
6+
Any parameter that does not match the column name
7+
8+
.NOTES
9+
Original link: https://nocolumnname.blog/2018/05/25/finding-parameters-that-do-not-match-column-names/
10+
Author: Shane O'Neill
11+
#>
12+
13+
$PatternMatch = '(?<ColumnName>\w+)\s*=\s*@(?<ParameterName>\w+)'
214

315
$FindStoredProcedureParameters = @{
416
SqlInstance = 'localhost'
@@ -23,4 +35,4 @@ Find-DbaStoredProcedure @FindStoredProcedureParameters |
2335
}
2436
}
2537
} | Where-Object { ($_.ColumnName -ne $_.ParameterName) } |
26-
Select-Object -Property * -Unique
38+
Select-Object -Property * -Unique

0 commit comments

Comments
 (0)