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).
36
2
function Export-SitecoreAzureSqlDatabase
37
3
{
38
4
param ([Parameter (Position = 0 , Mandatory = $true )]
39
5
[ValidateNotNullOrEmpty ()]
40
- [String ]
41
- $SqlServerName = " .\SQLEXPRESS " ,
6
+ [System. String ]
7
+ $SqlServerName ,
42
8
[Parameter (Position = 1 , Mandatory = $true )]
43
9
[ValidateNotNullOrEmpty ()]
44
- [String ]
45
- $SqlServerUser = " sa " ,
10
+ [System. String ]
11
+ $SqlServerUser ,
46
12
[Parameter (Position = 2 , Mandatory = $true )]
47
13
[ValidateNotNullOrEmpty ()]
48
- [String ]
49
- $SqlServerPassword = " 12345 " ,
14
+ [System. String ]
15
+ $SqlServerPassword ,
50
16
[Parameter (Position = 3 , Mandatory = $true )]
51
17
[ValidateNotNullOrEmpty ()]
52
- [String []]
18
+ [System. String []]
53
19
$SqlServerDatabaseList
54
20
)
55
21
@@ -87,18 +53,18 @@ function Export-SitecoreAzureSqlDatabase
87
53
return $outputDirectory
88
54
}
89
55
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 .
91
57
function Get-SitecoreAzureResourceGroup
92
58
{
93
59
[cmdletbinding ()]
94
60
param ([Parameter (Position = 0 , Mandatory = $true )]
95
61
[ValidateNotNullOrEmpty ()]
96
62
[System.String ]
97
- $Name = " Sitecore-Azure " ,
63
+ $Name ,
98
64
[Parameter (Position = 1 , Mandatory = $true )]
99
65
[ValidateNotNullOrEmpty ()]
100
66
[System.String ]
101
- $Location = " West US "
67
+ $Location
102
68
)
103
69
104
70
# Check if Azure Resource Group exists. If it does not, create it.
@@ -117,7 +83,7 @@ function Get-SitecoreAzureResourceGroup
117
83
return $resourceGroup
118
84
}
119
85
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.
121
87
function Get-SitecoreAzureStorageAccount
122
88
{
123
89
[cmdletbinding ()]
@@ -128,8 +94,8 @@ function Get-SitecoreAzureStorageAccount
128
94
[Parameter (Position = 1 , Mandatory = $true )]
129
95
[ValidateNotNullOrEmpty ()]
130
96
[System.String ]
131
- $AccountName = " sitecoreazure " ,
132
- [Parameter (Position = 3 , Mandatory = $false )]
97
+ $AccountName ,
98
+ [Parameter (Position = 2 , Mandatory = $false )]
133
99
[ValidateNotNullOrEmpty ()]
134
100
[System.String ]
135
101
$ContainerName = " databases"
@@ -174,7 +140,7 @@ function Get-SitecoreAzureStorageAccount
174
140
return $storageAccountContext
175
141
}
176
142
177
- # Upload local Sitecore BACPAC packages (*.bacpac files) to Azure Storage Blob.
143
+ # Uploads local Sitecore BACPAC packages (*.bacpac files) to a Storage Blob.
178
144
function Set-SitecoreAzureBacpacFile
179
145
{
180
146
[cmdletbinding ()]
@@ -199,7 +165,7 @@ function Set-SitecoreAzureBacpacFile
199
165
Get-AzureStorageBlob - Container $ContainerName - Context $StorageAccountContext | Out-Host
200
166
}
201
167
202
- # Creating an Azure SQL Server and setting up the firewall.
168
+ # Creates an Azure SQL Server and setting up the firewall.
203
169
function Get-SitecoreAzureSqlServer
204
170
{
205
171
[cmdletbinding ()]
@@ -210,7 +176,7 @@ function Get-SitecoreAzureSqlServer
210
176
[Parameter (Position = 1 , Mandatory = $true )]
211
177
[ValidateNotNullOrEmpty ()]
212
178
[System.String ]
213
- $ServerName = " sitecore-azure " ,
179
+ $ServerName ,
214
180
[Parameter (Position = 2 , Mandatory = $true )]
215
181
[ValidateNotNull ()]
216
182
[PSCredential ]
@@ -240,7 +206,7 @@ function Get-SitecoreAzureSqlServer
240
206
return $sqlServer
241
207
}
242
208
243
- # Setting an Azure SQL Server Firewall Rule.
209
+ # Sets an Azure SQL Server Firewall Rule.
244
210
function Set-SitecoreAzureSqlServerFirewallRule
245
211
{
246
212
[cmdletbinding ()]
@@ -296,7 +262,7 @@ function Set-SitecoreAzureSqlServerFirewallRule
296
262
}
297
263
}
298
264
299
- # Importing Azure SQL Databases from a Blob Storage.
265
+ # Imports Azure SQL Databases from a Blob Storage.
300
266
function Import-SitecoreAzureSqlDatabase
301
267
{
302
268
[cmdletbinding ()]
@@ -326,9 +292,7 @@ function Import-SitecoreAzureSqlDatabase
326
292
- Container $ContainerName
327
293
328
294
$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
+
332
296
# Import to Azure SQL Database using *.bacpac files from Azure Storage Account.
333
297
foreach ($blob in $blobList )
334
298
{
@@ -348,7 +312,7 @@ function Import-SitecoreAzureSqlDatabase
348
312
$sqlDatabase = New-AzureRmSqlDatabase –ResourceGroupName $ResourceGroup.ResourceGroupName `
349
313
–ServerName $SqlServerName `
350
314
–DatabaseName $databaseName `
351
- - RequestedServiceObjectiveName " S3 "
315
+ - RequestedServiceObjectiveName " S2 "
352
316
}
353
317
354
318
$sqlDatabaseServerContext = New-AzureSqlDatabaseServerContext - ServerName $SqlServerName `
@@ -369,7 +333,7 @@ function Import-SitecoreAzureSqlDatabase
369
333
return $importRequestList
370
334
}
371
335
372
- # Get a status of the import request.
336
+ # Gets a status of the import request.
373
337
function Get-SitecoreAzureSqlServerStatus
374
338
{
375
339
[cmdletbinding ()]
@@ -390,7 +354,6 @@ function Get-SitecoreAzureSqlServerStatus
390
354
{
391
355
for ($index = 0 ; $index -lt $ImportRequestList.Count ; $index ++ )
392
356
{
393
- # [Microsoft.WindowsAzure.Commands.SqlDatabase.Services.ImportExport.StatusInfo]$importStatus = Get-AzureSqlDatabaseImportExportStatus -Request $ImportRequestList[$index]
394
357
$importStatus = Get-AzureSqlDatabaseImportExportStatus - Request $ImportRequestList [$index ]
395
358
396
359
if ($importStatus.Status -eq " Failed" )
@@ -511,7 +474,7 @@ function Publish-SitecoreSqlDatabase
511
474
[Parameter (Position = 0 , Mandatory = $true )]
512
475
[ValidateNotNullOrEmpty ()]
513
476
[System.String ]
514
- $SqlServerName = " . \SQLEXPRESS" ,
477
+ $SqlServerName = " $ env: COMPUTERNAME \SQLEXPRESS" ,
515
478
516
479
[Parameter (Position = 1 , Mandatory = $true )]
517
480
[ValidateNotNullOrEmpty ()]
@@ -560,8 +523,6 @@ function Publish-SitecoreSqlDatabase
560
523
$AzureSqlServerPassword = " Experienc3!"
561
524
)
562
525
563
- Login- SitecoreAzureAccount
564
-
565
526
$outputDirectory = Export-SitecoreAzureSqlDatabase - sqlServerName $SqlServerName `
566
527
- sqlServerUser $SqlServerAdminLogin `
567
528
- sqlServerPassword $SqlServerPassword `
@@ -591,7 +552,7 @@ function Publish-SitecoreSqlDatabase
591
552
- StorageAccountContext $storageAccountContext
592
553
593
554
Get-SitecoreAzureSqlServerStatus - ImportRequestList $importRequestList
594
-
555
+
595
556
Get-SitecoreAzureSqlDatabaseConnectionString - ResourceGroup $resourceGroup `
596
557
- SqlServerName $AzureSqlServerName `
597
558
- AzureSqlServerAdminLogin $AzureSqlServerAdminLogin `
@@ -622,12 +583,12 @@ $paramHash = @{
622
583
DotNetFrameworkVersion = "4.0"
623
584
CLRVersion="4.0"
624
585
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 "}
631
592
)
632
593
RequiredAssemblies = @()
633
594
ScriptsToProcess = @()
0 commit comments