-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.ps1
40 lines (35 loc) · 2.42 KB
/
webapp.ps1
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
### Create Web App
$SubscriptionName = "Azure Pass" # This variable should be assigned your "Subscription Name"
$workFolder = "c:\labfiles.55264a\"
$TempFolder = "c:\temp\"
[Environment]::SetEnvironmentVariable("WORKFOLDER", $WorkFolder)
$Location = "EASTUS"
$NamePrefix = "web" + (Get-Date -Format "HHmmss") # Replace "web" with your initials
$ResourceGroupName = $NamePrefix + "rg"
$StorageAccountName = $NamePrefix.ToLower() + "sa" # Must be lower case
$AzureShareName = "labfiles"
$ServicePlanName = $NamePrefix + "spn"
$WebAppName = $NamePrefix + "app"
$GRPath = "https://github.com/Azure-Samples/app-service-web-html-get-started.git"
### Login to Azure
Connect-AzureRmAccount
$Subscription = Get-AzureRmSubscription -SubscriptionName $SubscriptionName | Select-AzureRmSubscription
### Create Resource Group, Storage Account & Azure Share
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $StorageAccountName -Location $location -Type Standard_RAGRS
$StorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $resourceGroupName -Name $StorageAccountName)[0].Value
$StorageAccountContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$StorageShare = New-AzureStorageShare $AzureShareName -Context $StorageAccountContext
### Create Service Plan and Web App
$SP = New-AzureRMAppServicePlan -ResourceGroupName $ResourceGroupName -Name $ServicePlanName -Location $Location -Tier "Free"
New-AzWebApp -ResourceGroupName $ResourceGroupName -WebAppName $WebAppName -AppServicePlan $ServicePlanName -GitRepositoryPath $GRPath -Auto
### Copy local file to Azure Share and verify
New-AzureStorageDirectory -Share $StorageShare -Path txtfiles
Get-ChildItem $WorkFolder"*.txt" -Recurse | Set-AzureStorageFileContent -Share $StorageShare -Path /txtfiles -Force
Get-AzureStorageFile -Sharename $AzureShareName -Context $StorageAccountContext
### Copy Azure Share file to local directory and verify
Get-AzureStorageFileContent -Share $StorageShare -Path password.txt -Destination $TempFolder -Force
Get-ChildItem $TempFolder
### Remove Resource Group and all objects associated with it
# Remove-AzureRMResourceGroup -Name $resourceGroupName -Force