1- # Adding the Azure account to Windows PowerShell.
2- function Login-SitecoreAzureAccount
3- {
4- [cmdletbinding ()]
5- param (
6- )
7-
8- try
9- {
10- $subscription = Get-AzureRmSubscription
11- }
12- catch
13- {
14- Login- AzureRmAccount
15- Get-AzureRmSubscription
16-
17- $subscriptionName = Read-Host - Prompt " Enter Subscription Name that you want to use"
18- Get-AzureRmSubscription –SubscriptionName $subscriptionName | Select-AzureRmSubscription
19- }
20-
21- <#
22- Get-AzureSubscription -Default -ErrorAction SilentlyContinue
23-
24- # Hack since the Get-AzureSubscription -Default cmdlet does not throw an exception.
25- $lastError = $Error.Item(0).ToString()
26- if ($lastError.StartsWith("No default subscription has been designated."))
27- {
28- Get-AzureRmSubscription
29- $subscriptionName = Read-Host -Prompt "Type Subscription Name that you want to use"
30- Get-AzureRmSubscription –SubscriptionName $subscriptionName | Select-AzureRmSubscription
31- }
32- #>
33- }
34-
35- # Exporting a database schema and user data from SQL Server to a BACPAC package (.bacpac file).
1+ # Exports a database schema and user data from a SQL Server to a BACPAC package (.bacpac file).
362function Export-SitecoreAzureSqlDatabase
373{
384 param ([Parameter (Position = 0 , Mandatory = $true )]
395 [ValidateNotNullOrEmpty ()]
40- [String ]
41- $SqlServerName = " .\SQLEXPRESS " ,
6+ [System. String ]
7+ $SqlServerName ,
428 [Parameter (Position = 1 , Mandatory = $true )]
439 [ValidateNotNullOrEmpty ()]
44- [String ]
45- $SqlServerUser = " sa " ,
10+ [System. String ]
11+ $SqlServerUser ,
4612 [Parameter (Position = 2 , Mandatory = $true )]
4713 [ValidateNotNullOrEmpty ()]
48- [String ]
49- $SqlServerPassword = " 12345 " ,
14+ [System. String ]
15+ $SqlServerPassword ,
5016 [Parameter (Position = 3 , Mandatory = $true )]
5117 [ValidateNotNullOrEmpty ()]
52- [String []]
18+ [System. String []]
5319 $SqlServerDatabaseList
5420 )
5521
@@ -87,18 +53,18 @@ function Export-SitecoreAzureSqlDatabase
8753 return $outputDirectory
8854}
8955
90- # Creating an Azure Resource Group for keeping resources such as Azure Storage, Azure SQL Server and Azure SQL Database.
56+ # Gets an Azure Resource Group for keeping resources such as Storage, SQL Server and SQL Database in one scope .
9157function Get-SitecoreAzureResourceGroup
9258{
9359 [cmdletbinding ()]
9460 param ([Parameter (Position = 0 , Mandatory = $true )]
9561 [ValidateNotNullOrEmpty ()]
9662 [System.String ]
97- $Name = " Sitecore-Azure " ,
63+ $Name ,
9864 [Parameter (Position = 1 , Mandatory = $true )]
9965 [ValidateNotNullOrEmpty ()]
10066 [System.String ]
101- $Location = " West US "
67+ $Location
10268 )
10369
10470 # Check if Azure Resource Group exists. If it does not, create it.
@@ -117,7 +83,7 @@ function Get-SitecoreAzureResourceGroup
11783 return $resourceGroup
11884}
11985
120- # Creating an Azure Storage and uploading a BACPAC packages (*.bacpac files) to a Container.
86+ # Creates an Azure Storage and uploading a BACPAC packages (*.bacpac files) to a Container.
12187function Get-SitecoreAzureStorageAccount
12288{
12389 [cmdletbinding ()]
@@ -128,8 +94,8 @@ function Get-SitecoreAzureStorageAccount
12894 [Parameter (Position = 1 , Mandatory = $true )]
12995 [ValidateNotNullOrEmpty ()]
13096 [System.String ]
131- $AccountName = " sitecoreazure " ,
132- [Parameter (Position = 3 , Mandatory = $false )]
97+ $AccountName ,
98+ [Parameter (Position = 2 , Mandatory = $false )]
13399 [ValidateNotNullOrEmpty ()]
134100 [System.String ]
135101 $ContainerName = " databases"
@@ -174,7 +140,7 @@ function Get-SitecoreAzureStorageAccount
174140 return $storageAccountContext
175141}
176142
177- # Upload local Sitecore BACPAC packages (*.bacpac files) to Azure Storage Blob.
143+ # Uploads local Sitecore BACPAC packages (*.bacpac files) to a Storage Blob.
178144function Set-SitecoreAzureBacpacFile
179145{
180146 [cmdletbinding ()]
@@ -199,7 +165,7 @@ function Set-SitecoreAzureBacpacFile
199165 Get-AzureStorageBlob - Container $ContainerName - Context $StorageAccountContext | Out-Host
200166}
201167
202- # Creating an Azure SQL Server and setting up the firewall.
168+ # Creates an Azure SQL Server and setting up the firewall.
203169function Get-SitecoreAzureSqlServer
204170{
205171 [cmdletbinding ()]
@@ -210,7 +176,7 @@ function Get-SitecoreAzureSqlServer
210176 [Parameter (Position = 1 , Mandatory = $true )]
211177 [ValidateNotNullOrEmpty ()]
212178 [System.String ]
213- $ServerName = " sitecore-azure " ,
179+ $ServerName ,
214180 [Parameter (Position = 2 , Mandatory = $true )]
215181 [ValidateNotNull ()]
216182 [PSCredential ]
@@ -240,7 +206,7 @@ function Get-SitecoreAzureSqlServer
240206 return $sqlServer
241207}
242208
243- # Setting an Azure SQL Server Firewall Rule.
209+ # Sets an Azure SQL Server Firewall Rule.
244210function Set-SitecoreAzureSqlServerFirewallRule
245211{
246212 [cmdletbinding ()]
@@ -296,7 +262,7 @@ function Set-SitecoreAzureSqlServerFirewallRule
296262 }
297263}
298264
299- # Importing Azure SQL Databases from a Blob Storage.
265+ # Imports Azure SQL Databases from a Blob Storage.
300266function Import-SitecoreAzureSqlDatabase
301267{
302268 [cmdletbinding ()]
@@ -326,9 +292,7 @@ function Import-SitecoreAzureSqlDatabase
326292 - Container $ContainerName
327293
328294 $importRequestList = New-Object System.Collections.Generic.List[System.Object ]
329-
330- # Import-AzurePublishSettingsFile -PublishSettingsFile "C:\Users\obu\Documents\Sitecore License\USA\Azure\Visual Studio Premium with MSDN-Sitecore US PSS OBU-10-17-2015-credentials.publishsettings" | Out-Host
331-
295+
332296 # Import to Azure SQL Database using *.bacpac files from Azure Storage Account.
333297 foreach ($blob in $blobList )
334298 {
@@ -348,7 +312,7 @@ function Import-SitecoreAzureSqlDatabase
348312 $sqlDatabase = New-AzureRmSqlDatabase –ResourceGroupName $ResourceGroup.ResourceGroupName `
349313 –ServerName $SqlServerName `
350314 –DatabaseName $databaseName `
351- - RequestedServiceObjectiveName " S3 "
315+ - RequestedServiceObjectiveName " S2 "
352316 }
353317
354318 $sqlDatabaseServerContext = New-AzureSqlDatabaseServerContext - ServerName $SqlServerName `
@@ -369,7 +333,7 @@ function Import-SitecoreAzureSqlDatabase
369333 return $importRequestList
370334}
371335
372- # Get a status of the import request.
336+ # Gets a status of the import request.
373337function Get-SitecoreAzureSqlServerStatus
374338{
375339 [cmdletbinding ()]
@@ -390,7 +354,6 @@ function Get-SitecoreAzureSqlServerStatus
390354 {
391355 for ($index = 0 ; $index -lt $ImportRequestList.Count ; $index ++ )
392356 {
393- # [Microsoft.WindowsAzure.Commands.SqlDatabase.Services.ImportExport.StatusInfo]$importStatus = Get-AzureSqlDatabaseImportExportStatus -Request $ImportRequestList[$index]
394357 $importStatus = Get-AzureSqlDatabaseImportExportStatus - Request $ImportRequestList [$index ]
395358
396359 if ($importStatus.Status -eq " Failed" )
@@ -511,7 +474,7 @@ function Publish-SitecoreSqlDatabase
511474 [Parameter (Position = 0 , Mandatory = $true )]
512475 [ValidateNotNullOrEmpty ()]
513476 [System.String ]
514- $SqlServerName = " . \SQLEXPRESS" ,
477+ $SqlServerName = " $ env: COMPUTERNAME \SQLEXPRESS" ,
515478
516479 [Parameter (Position = 1 , Mandatory = $true )]
517480 [ValidateNotNullOrEmpty ()]
@@ -560,8 +523,6 @@ function Publish-SitecoreSqlDatabase
560523 $AzureSqlServerPassword = " Experienc3!"
561524 )
562525
563- Login- SitecoreAzureAccount
564-
565526 $outputDirectory = Export-SitecoreAzureSqlDatabase - sqlServerName $SqlServerName `
566527 - sqlServerUser $SqlServerAdminLogin `
567528 - sqlServerPassword $SqlServerPassword `
@@ -591,7 +552,7 @@ function Publish-SitecoreSqlDatabase
591552 - StorageAccountContext $storageAccountContext
592553
593554 Get-SitecoreAzureSqlServerStatus - ImportRequestList $importRequestList
594-
555+
595556 Get-SitecoreAzureSqlDatabaseConnectionString - ResourceGroup $resourceGroup `
596557 - SqlServerName $AzureSqlServerName `
597558 - AzureSqlServerAdminLogin $AzureSqlServerAdminLogin `
@@ -622,12 +583,12 @@ $paramHash = @{
622583 DotNetFrameworkVersion = "4.0"
623584 CLRVersion="4.0"
624585 ProcessorArchitecture = "None"
625- RequiredModules = @(
626- @{ ModuleName = "AzureRM"; ModuleVersion = "0.9.11 "},
627- @{ ModuleName = "AzureRM"; ModuleVersion = "1.0.1"},
628- @{ ModuleName = "AzureRM.Resources"; ModuleVersion = "0.10.0 "},
629- @{ ModuleName = "AzureRM.Storage"; ModuleVersion = "0.10 .1"},
630- @{ ModuleName = "AzureRM.Sql"; ModuleVersion = "0.10.0 "}
586+ RequiredModules = @(
587+ @{ ModuleName = "AzureRM"; ModuleVersion = "1.0.2 "},
588+ @{ ModuleName = "AzureRM.profile "; ModuleVersion = "1.0.1"},
589+ @{ ModuleName = "AzureRM.Resources"; ModuleVersion = "1.0.1 "},
590+ @{ ModuleName = "AzureRM.Storage"; ModuleVersion = "1.0 .1"},
591+ @{ ModuleName = "AzureRM.Sql"; ModuleVersion = "1.0.1 "}
631592 )
632593 RequiredAssemblies = @()
633594 ScriptsToProcess = @()
0 commit comments