Skip to content
This repository was archived by the owner on Nov 10, 2017. It is now read-only.

Commit d84e7aa

Browse files
committed
Issue #9 was implemented.
Outputting connection strings as table makes them look better, but there is an issue with the 'ConnectionString' column. It is too wide. Even the -AutoSize parameters does not help. Write-Host ($connectionStringList| Format-Table -AutoSize | Out-String) Therefore, connection string is outputted as a list. Write-Host ($connectionStringList| Format-List | Out-String)
1 parent 28fa38e commit d84e7aa

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/Sitecore.Azure/Sitecore.Azure.psm1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,54 @@ function Get-SitecoreAzureSqlServerStatus
437437

438438
Write-Progress -Id 0 -activity "Start-AzureSqlDatabaseImport task status:" -Completed
439439
}
440+
441+
# Gets Azure SQL Database connection string.
442+
function Get-SitecoreAzureSqlDatabaseConnectionString
443+
{
444+
[cmdletbinding()]
445+
param([Parameter(Position=0, Mandatory = $true)]
446+
[ValidateNotNull()]
447+
[Microsoft.Azure.Commands.Resources.Models.PSResourceGroup]
448+
$ResourceGroup,
449+
[Parameter(Position=1, Mandatory = $true)]
450+
[ValidateNotNullOrEmpty()]
451+
[System.String]
452+
$SqlServerName,
453+
[Parameter(Position=2, Mandatory = $true)]
454+
[ValidateNotNullOrEmpty()]
455+
[System.String]
456+
$AzureSqlServerAdminLogin,
457+
[Parameter(Position=3, Mandatory = $true)]
458+
[ValidateNotNullOrEmpty()]
459+
[System.String]
460+
$AzureSqlServerPassword
461+
)
462+
463+
$sqlDatabaseList = Get-AzureRmSqlDatabase -ResourceGroupName $ResourceGroup.ResourceGroupName `
464+
-ServerName $SqlServerName
465+
466+
$connectionStringList = New-Object System.Collections.Generic.List[System.Object]
467+
468+
foreach ($database in $sqlDatabaseList)
469+
{
470+
if ($database.DatabaseName -ne "master")
471+
{
472+
$secureConnectionPolicy = Get-AzureRmSqlDatabaseSecureConnectionPolicy -ResourceGroupName $ResourceGroup.ResourceGroupName `
473+
-ServerName $SqlServerName `
474+
-DatabaseName $database.DatabaseName
475+
476+
$info = @{
477+
DatabaseName = $database.DatabaseName;
478+
ConnectionString = $secureConnectionPolicy.ConnectionStrings.AdoNetConnectionString.Replace("{your_user_id_here}", $AzureSqlServerAdminLogin).Replace("{your_password_here}", $AzureSqlServerPassword)
479+
}
480+
481+
$connectionStringList.Add((New-Object -Type PSObject -Property $info))
482+
}
483+
}
484+
485+
Write-Host ($connectionStringList| Format-List | Out-String)
486+
}
487+
440488
<#
441489
.SYNOPSIS
442490
Describe the function here
@@ -542,6 +590,11 @@ function Publish-SitecoreSqlDatabase
542590
-StorageAccountContext $storageAccountContext
543591

544592
Get-SitecoreAzureSqlServerStatus -ImportRequestList $importRequestList
593+
594+
Get-SitecoreAzureSqlDatabaseConnectionString -ResourceGroup $resourceGroup `
595+
-SqlServerName $AzureSqlServerName `
596+
-AzureSqlServerAdminLogin $AzureSqlServerAdminLogin `
597+
-AzureSqlServerPassword $AzureSqlServerPassword
545598

546599
Remove-Item $outputDirectory -Recurse -Force
547600
}

0 commit comments

Comments
 (0)