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

Commit 993e798

Browse files
committed
Implemented issue #11.
1 parent 79afc81 commit 993e798

File tree

1 file changed

+50
-83
lines changed

1 file changed

+50
-83
lines changed

src/Sitecore.Azure/Sitecore.Azure.psm1

+50-83
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ function Export-SitecoreAzureSqlDatabase
44
param([Parameter(Position=0, Mandatory = $true)]
55
[ValidateNotNullOrEmpty()]
66
[System.String]
7-
$SqlServerName,
7+
$SqlServerName,
88
[Parameter(Position=1, Mandatory = $true)]
9-
[ValidateNotNullOrEmpty()]
10-
[System.String]
11-
$SqlServerUser,
9+
[ValidateNotNull()]
10+
[System.Management.Automation.PSCredential]
11+
$SqlServerCredentials,
1212
[Parameter(Position=2, Mandatory = $true)]
1313
[ValidateNotNullOrEmpty()]
14-
[System.String]
15-
$SqlServerPassword,
16-
[Parameter(Position=3, Mandatory = $true)]
17-
[ValidateNotNullOrEmpty()]
1814
[System.String[]]
1915
$SqlServerDatabaseList
2016
)
@@ -35,8 +31,8 @@ function Export-SitecoreAzureSqlDatabase
3531

3632
&$sqlpackageExe /a:Export `
3733
/ssn:$SqlServerName `
38-
/su:$SqlServerUser `
39-
/sp:$SqlServerPassword `
34+
/su:$($SqlServerCredentials.UserName) `
35+
/sp:$($SqlServerCredentials.GetNetworkCredential().Password) `
4036
/sdn:$databaseName `
4137
/tf:$filePath | Out-Host
4238

@@ -179,8 +175,8 @@ function Get-SitecoreAzureSqlServer
179175
$ServerName,
180176
[Parameter(Position=2, Mandatory = $true)]
181177
[ValidateNotNull()]
182-
[PSCredential]
183-
$SqlAdministratorCredentials
178+
[System.Management.Automation.PSCredential]
179+
$SqlServerCredentials
184180
)
185181

186182
# Check if Azure SQL Server instance exists. If it does not, create it.
@@ -195,7 +191,7 @@ function Get-SitecoreAzureSqlServer
195191
$sqlServer = New-AzureRmSqlServer -ResourceGroupName $ResourceGroup.ResourceGroupName `
196192
-Location $ResourceGroup.Location `
197193
-ServerName $azureSqlServerName `
198-
-SqlAdministratorCredentials $SqlAdministratorCredentials `
194+
-SqlAdministratorCredentials $SqlServerCredentials `
199195
-ServerVersion "12.0"
200196
}
201197

@@ -276,8 +272,8 @@ function Import-SitecoreAzureSqlDatabase
276272
$SqlServerName,
277273
[Parameter(Position=2, Mandatory = $true)]
278274
[ValidateNotNullOrEmpty()]
279-
[PSCredential]
280-
$SqlAdministratorCredentials,
275+
[System.Management.Automation.PSCredential]
276+
$SqlServerCredentials,
281277
[Parameter(Position=3, Mandatory = $false)]
282278
[ValidateNotNullOrEmpty()]
283279
[System.String]
@@ -316,7 +312,7 @@ function Import-SitecoreAzureSqlDatabase
316312
}
317313

318314
$sqlDatabaseServerContext = New-AzureSqlDatabaseServerContext -ServerName $SqlServerName `
319-
-Credential $SqlAdministratorCredentials
315+
-Credential $SqlServerCredentials
320316

321317
if ($sqlDatabaseServerContext -ne $null)
322318
{
@@ -415,13 +411,9 @@ function Get-SitecoreAzureSqlDatabaseConnectionString
415411
[System.String]
416412
$SqlServerName,
417413
[Parameter(Position=2, Mandatory = $true)]
418-
[ValidateNotNullOrEmpty()]
419-
[System.String]
420-
$AzureSqlServerAdminLogin,
421-
[Parameter(Position=3, Mandatory = $true)]
422-
[ValidateNotNullOrEmpty()]
423-
[System.String]
424-
$AzureSqlServerPassword
414+
[ValidateNotNull()]
415+
[System.Management.Automation.PSCredential]
416+
$SqlServerCredentials
425417
)
426418

427419
$sqlDatabaseList = Get-AzureRmSqlDatabase -ResourceGroupName $ResourceGroup.ResourceGroupName `
@@ -439,7 +431,7 @@ function Get-SitecoreAzureSqlDatabaseConnectionString
439431

440432
$info = @{
441433
DatabaseName = $database.DatabaseName;
442-
ConnectionString = $secureConnectionPolicy.ConnectionStrings.AdoNetConnectionString.Replace("{your_user_id_here}", $AzureSqlServerAdminLogin).Replace("{your_password_here}", $AzureSqlServerPassword)
434+
ConnectionString = $secureConnectionPolicy.ConnectionStrings.AdoNetConnectionString.Replace("{your_user_id_here}", $SqlServerCredentials.UserName).Replace("{your_password_here}", $SqlServerCredentials.GetNetworkCredential().Password)
443435
}
444436

445437
$connectionStringList.Add((New-Object -Type PSObject -Property $info))
@@ -469,13 +461,10 @@ function Get-SitecoreAzureSqlDatabaseConnectionString
469461
https://github.com/olegburov/Sitecore-Azure-PowerShell/
470462
471463
.PARAMETER SqlServerName
472-
Specifies the name of the local SQL Server the databases are in. The name must be in the following format {ComputerName}\{InstanceName}, such as "Oleg-PC\SQLEXPRESS".
473-
474-
.PARAMETER SqlServerAdminLogin
475-
Specifies the SQL Server administrator name for the local server.
464+
Specifies the name of the local SQL Server the databases are in. The name must be in the following format {ComputerName}\{InstanceName}, for example "Oleg-PC\SQLEXPRESS".
476465
477-
.PARAMETER SqlServerPassword
478-
Specifies the SQL Server administrator password for the local server.
466+
.PARAMETER SqlServerCredentials
467+
Specifies the SQL Server administrator credentials for the local server.
479468
480469
.PARAMETER SqlServerDatabaseList
481470
Specifies the list of the database names to retrieve from a local server.
@@ -492,16 +481,11 @@ function Get-SitecoreAzureSqlDatabaseConnectionString
492481
.PARAMETER AzureSqlServerName
493482
Specifies the name of the new SQL Database server. The server name must be globally unique.
494483
495-
.PARAMETER AzureSqlServerAdminLogin
496-
Specifies the SQL Database server administrator name for the new server.
497-
498-
.PARAMETER AzureSqlServerPassword
499-
Specifies the SQL Database server administrator password for the new server.
500-
484+
.PARAMETER AzureSqlServerCredential
485+
Specifies the SQL Database server administrator credentials for the new server.
501486
502-
503-
.EXAMPLE
504-
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerAdminLogin "sa" -SqlServerPassword "12345" -SqlServerDatabaseList @("sc81initial_core", "sc81initial_master", "sc81initial_web")
487+
.EXAMPLE
488+
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerCredentials $credentials -SqlServerDatabaseList @("sc81initial_core", "sc81initial_master", "sc81initial_web")
505489
506490
This command publishes the SQL Server database "sc81initial_core", "sc81initial_master" and "sc81initial_web" from the local SQL Server "Oleg-PC\SQLEXPRESS" to an Azure SQL Database Server.
507491
@@ -520,9 +504,9 @@ function Get-SitecoreAzureSqlDatabaseConnectionString
520504
ID=sitecore@sitecore-azure-50876f04;Password=Experienc3!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30
521505
522506
.EXAMPLE
523-
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerAdminLogin "sa" -SqlServerPassword "12345" -SqlServerDatabaseList @("sc81initial_web") -AzureResourceGroupName "My-Company-Name" -AzureResourceGroupLocation "Australia East"
507+
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerCredentials $credentials -SqlServerDatabaseList @("sc81initial_web") -AzureResourceGroupName "MyCompanyName" -AzureResourceGroupLocation "Australia East"
524508
525-
This command publishes the SQL Server databases "sc81initial_web" from the local SQL Server "Oleg-PC\SQLEXPRESS" to an Azure SQL Database Server in the Resource Group "My-Company-Name" at the Azure data center "Australia East".
509+
This command publishes the SQL Server databases "sc81initial_web" from the local SQL Server "Oleg-PC\SQLEXPRESS" to an Azure SQL Database Server in the Resource Group "MyCompanyName" at the Azure data center "Australia East".
526510
527511
528512
@@ -531,7 +515,7 @@ function Get-SitecoreAzureSqlDatabaseConnectionString
531515
ID=sitecore@sitecore-azure-50876f04;Password=Experienc3!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30
532516
533517
.EXAMPLE
534-
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerAdminLogin "sa" -SqlServerPassword "12345" -SqlServerDatabaseList @("sc81initial_core", "sc81initial_web") -AzureStorageAccountName "mycompanyname"
518+
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerCredentials $credentials -SqlServerDatabaseList @("sc81initial_core", "sc81initial_web") -AzureStorageAccountName "mycompanyname"
535519
536520
This command publishes the SQL Server databases "sc81initial_core" and "sc81initial_web" from the local SQL Server "Oleg-PC\SQLEXPRESS" to an Azure SQL Database Server using the Azure Storage Account "mycompanyname" for BACPAC packages (.bacpac files).
537521
@@ -545,10 +529,10 @@ function Get-SitecoreAzureSqlDatabaseConnectionString
545529
ConnectionString : Server=tcp:sitecore-azure-50876f04.database.secure.windows.net,1433;Database=sc81initial_web;User
546530
ID=sitecore@sitecore-azure-50876f04;Password=Experienc3!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30
547531
548-
.EXAMPLE
549-
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerAdminLogin "sa" -SqlServerPassword "12345" -SqlServerDatabaseList @("sc81initial_core", "sc81initial_master", "sc81initial_web") -AzureSqlServerName "sitecore-azure" -AzureSqlServerAdminLogin "sitecore" -AzureSqlServerPassword "Experienc3!"
532+
.EXAMPLE
533+
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerCredentials $localSqlServerCredentials -SqlServerDatabaseList @("sc81initial_core", "sc81initial_master", "sc81initial_web") -AzureSqlServerName "sitecore-azure" -AzureSqlServerCredentials $azureSqlServerCredentials
550534
551-
This command publishes the SQL Server databases "sc81initial_core", "sc81initial_master" and "sc81initial_web" from the local SQL Server "Oleg-PC\SQLEXPRESS" to an Azure SQL Database Server in the Azure data center "West Europe".
535+
This command publishes the SQL Server databases "sc81initial_core", "sc81initial_master" and "sc81initial_web" from the local SQL Server "Oleg-PC\SQLEXPRESS" to an Azure SQL Database Server with specified credentials.
552536
553537
554538
@@ -564,10 +548,10 @@ function Get-SitecoreAzureSqlDatabaseConnectionString
564548
ConnectionString : Server=tcp:sitecore-azure.database.secure.windows.net,1433;Database=sc81initial_web;User
565549
ID=sitecore@sitecore-azure;Password=Experienc3!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30
566550
567-
.EXAMPLE
568-
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerAdminLogin "sa" -SqlServerPassword "12345" -SqlServerDatabaseList @("sc81initial_core", "sc81initial_master", "sc81initial_web", "sc81initial_reporting") -AzureResourceGroupName "My-Company-Name" -AzureResourceGroupLocation "West Europe" -AzureStorageAccountName "mycompanyname" -AzureSqlServerName "sitecore-azure" -AzureSqlServerAdminLogin "sitecore" -AzureSqlServerPassword "Experienc3!"
551+
.EXAMPLE
552+
PS C:\> Publish-SitecoreSqlDatabase -SqlServerName "Oleg-PC\SQLEXPRESS" -SqlServerCredentials $localSqlServerCredentials -SqlServerDatabaseList @("sc81initial_core", "sc81initial_master", "sc81initial_web", "sc81initial_reporting") -AzureResourceGroupName "MyCompanyName" -AzureResourceGroupLocation "West Europe" -AzureStorageAccountName "mycompanyname" -AzureSqlServerName "sitecore-azure" -AzureSqlServerCredentials $azureSqlServerCredentials
569553
570-
This command publishes the SQL Server databases "sc81initial_core", "sc81initial_master" and "sc81initial_web" from the local SQL Server "Oleg-PCU\SQLEXPRESS" to Azure SQL Database Server "sitecore-azure" in the Resource Group "My-Company-Name" at the Azure data center "West Europe" using the Azure Storage Account "mycompanyname".
554+
This command publishes the SQL Server databases "sc81initial_core", "sc81initial_master" and "sc81initial_web" from the local SQL Server "Oleg-PC\SQLEXPRESS" to Azure SQL Database Server "sitecore-azure" in the Resource Group "MyCompanyName" at the Azure data center "West Europe" using the Azure Storage Account "mycompanyname".
571555
572556
573557
@@ -595,56 +579,45 @@ function Publish-SitecoreSqlDatabase
595579
[System.String]
596580
$SqlServerName = "$env:COMPUTERNAME\SQLEXPRESS",
597581

598-
[Parameter(Position=1, Mandatory = $true)]
599-
[ValidateNotNullOrEmpty()]
600-
[System.String]
601-
$SqlServerAdminLogin,
602-
603-
[Parameter(Position=2, Mandatory = $true)]
604-
[ValidateNotNullOrEmpty()]
605-
[System.String]
606-
$SqlServerPassword,
582+
[Parameter(Position=1, Mandatory = $true)]
583+
[ValidateNotNull()]
584+
[System.Management.Automation.PSCredential]
585+
$SqlServerCredentials,
607586

608-
[Parameter(Position=3, Mandatory = $true)]
587+
[Parameter(Position=2, Mandatory = $true)]
609588
[ValidateNotNullOrEmpty()]
610589
[System.String[]]
611590
$SqlServerDatabaseList,
612591

613-
[Parameter(Position=4, Mandatory = $false)]
592+
[Parameter(Position=3, Mandatory = $false)]
614593
[ValidateNotNullOrEmpty()]
615594
[System.String]
616595
$AzureResourceGroupName = "Sitecore-Azure",
617596

618-
[Parameter(Position=5, Mandatory = $false)]
597+
[Parameter(Position=4, Mandatory = $false)]
619598
[ValidateNotNullOrEmpty()]
620599
[System.String]
621600
$AzureResourceGroupLocation = 'West US',
622601

623-
[Parameter(Position=6, Mandatory = $false)]
602+
[Parameter(Position=5, Mandatory = $false)]
624603
[ValidateNotNullOrEmpty()]
625604
[ValidateLength(3, 24)]
626605
[System.String]
627606
$AzureStorageAccountName = "sitecoreazure{0}" -f (Get-AzureRmContext).Subscription.SubscriptionId.Substring(0, 8),
628607

629-
[Parameter(Position=7, Mandatory = $false)]
608+
[Parameter(Position=6, Mandatory = $false)]
630609
[ValidateNotNullOrEmpty()]
631610
[System.String]
632611
$AzureSqlServerName = "sitecore-azure-{0}" -f (Get-AzureRmContext).Subscription.SubscriptionId.Substring(0, 8),
633612

634-
[Parameter(Position=8, Mandatory = $false)]
635-
[ValidateNotNullOrEmpty()]
636-
[System.String]
637-
$AzureSqlServerAdminLogin = "sitecore",
638-
639-
[Parameter(Position=9, Mandatory = $false)]
640-
[ValidateNotNullOrEmpty()]
641-
[System.String]
642-
$AzureSqlServerPassword = "Experienc3!"
613+
[Parameter(Position=7, Mandatory = $false)]
614+
[ValidateNotNull()]
615+
[System.Management.Automation.PSCredential]
616+
$AzureSqlServerCredentials = (New-Object System.Management.Automation.PSCredential ("sitecore", (ConvertTo-SecureString "Experienc3!" -AsPlainText -Force)))
643617
)
644618

645-
$outputDirectory = Export-SitecoreAzureSqlDatabase -sqlServerName $SqlServerName `
646-
-sqlServerUser $SqlServerAdminLogin `
647-
-sqlServerPassword $SqlServerPassword `
619+
$outputDirectory = Export-SitecoreAzureSqlDatabase -SqlServerName $SqlServerName `
620+
-SqlServerCredentials $SqlServerCredentials `
648621
-sqlServerDatabaseList $SqlServerDatabaseList
649622

650623
$resourceGroup = Get-SitecoreAzureResourceGroup -Name $AzureResourceGroupName `
@@ -655,27 +628,21 @@ function Publish-SitecoreSqlDatabase
655628

656629
Set-SitecoreAzureBacpacFile -Directory $outputDirectory `
657630
-StorageAccountContext $storageAccountContext
658-
659-
# The password for Azure SQL Server credentials.
660-
$securedPassword = ConvertTo-SecureString $AzureSqlServerPassword -AsPlainText -Force
661-
# The Azure SQL Server credentials.
662-
$credentials = New-Object System.Management.Automation.PSCredential ($AzureSqlServerAdminLogin, $securedPassword)
663631

664632
$SqlServer = Get-SitecoreAzureSqlServer -ResourceGroup $resourceGroup `
665633
-ServerName $AzureSqlServerName `
666-
-SqlAdministratorCredentials $credentials
634+
-SqlServerCredentials $AzureSqlServerCredentials
667635

668636
$importRequestList = Import-SitecoreAzureSqlDatabase -ResourceGroup $resourceGroup `
669637
-SqlServerName $AzureSqlServerName `
670-
-SqlAdministratorCredentials $credentials `
638+
-SqlServerCredentials $AzureSqlServerCredentials `
671639
-StorageAccountContext $storageAccountContext
672640

673641
Get-SitecoreAzureSqlServerStatus -ImportRequestList $importRequestList
674642

675643
Get-SitecoreAzureSqlDatabaseConnectionString -ResourceGroup $resourceGroup `
676644
-SqlServerName $AzureSqlServerName `
677-
-AzureSqlServerAdminLogin $AzureSqlServerAdminLogin `
678-
-AzureSqlServerPassword $AzureSqlServerPassword
645+
-SqlServerCredentials $AzureSqlServerCredentials
679646

680647
Remove-Item $outputDirectory -Recurse -Force
681648
}

0 commit comments

Comments
 (0)