|
1 | 1 | <# |
2 | 2 | .Synopsis |
3 | | - Clone a SQL Server Login based on another exsiting login. |
| 3 | + Clone a SQL Server Login based on another exsiting login. |
| 4 | +
|
4 | 5 | .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 | +
|
6 | 8 | .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" |
10 | 12 | |
11 | 13 | .EXAMPLE |
12 | 14 | 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" |
13 | 15 | also the -Execute parameter means the new account "David" will be created |
14 | 16 | Clone-SQLLogin -Server Server1, Server2 -OldLogin John -NewLogin David -NewPassword 'P@$$W0rd' -FilePath "c:\temp\clone.sql" -Execute; |
15 | | - |
| 17 | +
|
16 | 18 | .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 | +
|
19 | 21 | .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 | +
|
22 | 24 | .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 | +
|
25 | 27 | .Parameter NewPassword |
26 | 28 | The password for the new login account if we want to create the login, default to empty string "" (optional) |
27 | | - |
| 29 | +
|
28 | 30 | .Parameter FilePath |
29 | | - The full path name for the generated sql script (optional) |
| 31 | + The full path name for the generated sql script (optional) |
30 | 32 | |
31 | 33 | .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 | +
|
34 | 36 | .OUTPUTS |
35 | | - none |
| 37 | + none |
| 38 | +
|
36 | 39 | .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 |
40 | 43 | #> |
41 | 44 | #requires -version 3.0 |
42 | 45 | add-type -assembly "Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"; #if Version-11.xx means sql server 2012 |
|
0 commit comments