Skip to content

Commit

Permalink
Add -Encrypt parameter to Invoke-SqlCmd2 and New-SqlConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmcnabb committed Apr 4, 2016
1 parent c3f4c24 commit 718ecdf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
32 changes: 23 additions & 9 deletions Invoke-Sqlcmd2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
SECURITY NOTE: If you use the -Debug switch, the connectionstring including plain text password will be sent to the debug stream.
.PARAMETER Encrypt
If specified, will request that the connection to the SQL is done over SSL. This requires that the SQL Server has been set up to accept SSL requests. For information regarding setting up SSL on SQL Server, visit this link: https://technet.microsoft.com/en-us/library/ms189067(v=sql.105).aspx
.PARAMETER QueryTimeout
Specifies the number of seconds before the queries time out.
Expand Down Expand Up @@ -240,54 +243,65 @@
[System.Management.Automation.PSCredential]
$Credential,

[Parameter( Position=4,
[Parameter( ParameterSetName='Ins-Que',
Position=4,
Mandatory=$false,
ValueFromRemainingArguments=$false)]
[Parameter( ParameterSetName='Ins-Fil',
Position=4,
Mandatory=$false,
ValueFromRemainingArguments=$false)]
[switch]
$Encrypt,

[Parameter( Position=5,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false )]
[Int32]
$QueryTimeout=600,

[Parameter( ParameterSetName='Ins-Fil',
Position=5,
Position=6,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false )]
[Parameter( ParameterSetName='Ins-Que',
Position=5,
Position=6,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false )]
[Int32]
$ConnectionTimeout=15,

[Parameter( Position=6,
[Parameter( Position=7,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false )]
[ValidateSet("DataSet", "DataTable", "DataRow","PSObject","SingleValue")]
[string]
$As="DataRow",

[Parameter( Position=7,
[Parameter( Position=8,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false )]
[System.Collections.IDictionary]
$SqlParameters,

[Parameter( Position=8,
[Parameter( Position=9,
Mandatory=$false )]
[switch]
$AppendServerInstance,

[Parameter( ParameterSetName = 'Con-Que',
Position=9,
Position=10,
Mandatory=$false,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$false,
ValueFromRemainingArguments=$false )]
[Parameter( ParameterSetName = 'Con-Fil',
Position=9,
Position=10,
Mandatory=$false,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$false,
Expand Down Expand Up @@ -409,7 +423,7 @@
{
if ($Credential)
{
$ConnectionString = "Server={0};Database={1};User ID={2};Password=`"{3}`";Trusted_Connection=False;Connect Timeout={4}" -f $SQLInstance,$Database,$Credential.UserName,$Credential.GetNetworkCredential().Password,$ConnectionTimeout
$ConnectionString = "Server={0};Database={1};User ID={2};Password=`"{3}`";Trusted_Connection=False;Connect Timeout={4};Encrypt={5}" -f $SQLInstance,$Database,$Credential.UserName,$Credential.GetNetworkCredential().Password,$ConnectionTimeout,$Encrypt
}
else
{
Expand Down
13 changes: 11 additions & 2 deletions New-SQLConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
SECURITY NOTE: If you use the -Debug switch, the connectionstring including plain text password will be sent to the debug stream.
.PARAMETER Encrypt
If specified, will request that the connection to the SQL is done over SSL. This requires that the SQL Server has been set up to accept SSL requests. For information regarding setting up SSL on SQL Server, visit this link: https://technet.microsoft.com/en-us/library/ms189067(v=sql.105).aspx
.PARAMETER ConnectionTimeout
Specifies the number of seconds when New-SQLConnection times out if it cannot successfully connect to an instance of the Database Engine. The timeout value must be an integer between 0 and 65534. If 0 is specified, connection attempts do not time out.
Expand Down Expand Up @@ -66,13 +69,19 @@
$Credential,

[Parameter( Position=3,
Mandatory=$false,
ValueFromRemainingArguments=$false)]
[switch]
$Encrypt,

[Parameter( Position=4,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false )]
[Int32]
$ConnectionTimeout=15,

[Parameter( Position=4,
[Parameter( Position=5,
Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false )]
Expand All @@ -87,7 +96,7 @@

if ($Credential)
{
$ConnectionString = "Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;Connect Timeout={4}" -f $SQLInstance,$Database,$Credential.UserName,$Credential.GetNetworkCredential().Password,$ConnectionTimeout
$ConnectionString = "Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;Connect Timeout={4};Encrypt={5}" -f $SQLInstance,$Database,$Credential.UserName,$Credential.GetNetworkCredential().Password,$ConnectionTimeout,$Encrypt
}
else
{
Expand Down

0 comments on commit 718ecdf

Please sign in to comment.