/
AzureEnvironmentBuilder.psm1
161 lines (132 loc) · 6.88 KB
/
AzureEnvironmentBuilder.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<#
.SYNOPSIS
The New-SPDscAzureLab cmdlet will create a new environment in Azure that can be used to develop
for SharePointDsc or to run integration tests against
.DESCRIPTION
The New-SPDscAzureLab cmdlet will deploy a new resource group in to your current Azure subscription
that will contain storage, network and virtual machines that are configured to be able to begin
development. Appropriate development tools are also installed on the SharePoint server.
.PARAMETER ResourceGroupName
The name of the resource group to create and deploy assets in to. This cannot be an existing
resource group
.PARAMETER Location
The Azure location to deploy the assets and resource group to. To discover Azure locations run
Get-AzureRmLocation | Select-Object -Property Location
.PARAMETER StorageAccountName
This is the name of the storage account that will be created for the deployment. This will
contain VHD images, scripts and DSC configurations
.PARAMETER SoftwareStorageAccountName
This is the name of a storage account that will contain the binaries for SharePoint Server
(either 2013 or 2016).
.PARAMETER SoftwareStorageAccountContainer
This is the name of the container in the software storage account that will contain the
binaries for the version of SharePoint you wish to deploy. This must be the full set of
files to install SharePoint (not an ISO or other compressed collection of the files)
.PARAMETER SharePointProductKey
A valid product key for the version of SharePoint you wish to install
.PARAMETER PublicDNSLabel
The name of the public DNS label to assign to the public IP address of the SharePoint server.
This will automatically be suffixed with the Azure location name and azure DNS suffix
.PARAMETER AdminCredential
The username and password to use as the local administrator on all machines. The password
on this account will also be used for all service accounts
.EXAMPLE
New-SPDscAzureLab -ResourceGroupName "SPDSCTestLab" `
-Location southeastasia `
-StorageAccountName "spdsctestlab1" `
-SoftwareStorageAccountName "spdscsoftware1" `
-SoftwareStorageAccountContainer "sharepoint2016" `
-SharePointProductKey "AAAAA-AAAAA-AAAAA-AAAAA-AAAAA" `
-PublicDNSLabel "spdsctestlab1" `
-AdminCredential (Get-Credential -Message "Enter admin credential")
.NOTES
This cmdlet requires that the Azure PowerShell cmdlets are already installed, and that you
have already run Login-AzureRmAccount to log in to Azure
#>
function New-SPDscAzureLab
{
param(
[Parameter(Mandatory = $true)]
[string]
$ResourceGroupName,
[Parameter(Mandatory = $true)]
[string]
$Location,
[Parameter(Mandatory = $true)]
[string]
$StorageAccountName,
[Parameter(Mandatory = $true)]
[string]
$SoftwareStorageAccountName,
[Parameter(Mandatory = $true)]
[string]
$SoftwareStorageAccountContainer,
[Parameter(Mandatory = $true)]
[string]
$SharePointProductKey,
[Parameter(Mandatory = $true)]
[string]
$PublicDNSLabel,
[Parameter(Mandatory = $true)]
[PSCredential]
$AdminCredential
)
# Get the Azure environment
$azureEnvironment = ( Get-AzureRmSubscription | Select-Object -ExpandProperty ExtendedProperties ).Environment |
Select-Object -Unique
# Create the RG and storage account
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
$storageAccount = New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName `
-Name $StorageAccountName `
-SkuName Standard_LRS `
-Location $Location
# Publish the DSC configurations
$dscConfigPath = Join-Path -Path $PSScriptRoot -ChildPath "DscConfigs"
Get-ChildItem -Path $dscConfigPath | ForEach-Object -Process {
Publish-AzureRmVMDscConfiguration -ConfigurationPath $_.FullName `
-ResourceGroupName $ResourceGroupName `
-StorageAccountName $StorageAccountName
}
# Publish the scripts
New-AzureStorageContainer -Name "scripts" -Context $storageAccount.Context
$scriptsPath = Join-Path -Path $PSScriptRoot -ChildPath "CustomScripts"
Get-ChildItem -Path $scriptsPath | ForEach-Object -Process {
Set-AzureStorageBlobContent -File $_.FullName `
-Container "scripts" `
-Blob $_.Name `
-Context $storageAccount.Context
}
# Get Sas token for DSC storage
$mainKeys = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName `
-Name $StorageAccountName
$mainStorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName `
-StorageAccountKey $mainKeys[0].Value
$mainSasToken = New-AzureStorageAccountSASToken -Service Blob `
-ResourceType Service,Container,Object `
-Permission "racwdlup" `
-Context $mainStorageContext
# Get keys for software storage
$storageAccount = Get-AzureRmResource -ResourceName $SoftwareStorageAccountName
$softwareKeys = Get-AzureRmStorageAccountKey -ResourceGroupName $storageAccount.ResourceGroupName `
-Name $SoftwareStorageAccountName
$parameters = @{}
$parameters.Add("azureEnvironment", $azureEnvironment)
$parameters.Add("storageAccountName", $StorageAccountName)
$parameters.Add("storageAccountKey", $mainKeys[0].Value)
$parameters.Add("softwareStorageAccount", $SoftwareStorageAccountName)
$parameters.Add("softwareStorageKey", $softwareKeys[0].Value)
$parameters.Add("softwareStorageContainer", $SoftwareStorageAccountContainer)
$parameters.Add("spProductKey", $SharePointProductKey)
$parameters.Add("adminUserName", $AdminCredential.UserName)
$parameters.Add("adminPassword", $AdminCredential.GetNetworkCredential().Password)
$parameters.Add("mainStorageToken", $mainSasToken)
$parameters.Add("publicDnsLabel", $PublicDNSLabel)
# Start the ARM deployment
$templatePath = Join-Path -Path $PSScriptRoot -ChildPath "template.json"
New-AzureRmResourceGroupDeployment -Name "SPDscLab" `
-TemplateFile $templatePath `
-ResourceGroupName $ResourceGroupName `
-TemplateParameterObject $parameters `
-Verbose
}
Export-ModuleMember -Function *