我创建了一个Azure Function应用。以前,我是在Visual Studio中使用GUI发布的。现在,我想使用Powershell脚本执行此操作。
我试图在MS Docs Azure RM PowerShell 6.13.0上找到,但没有得到任何东西(或者我错过了一些东西)
那我该怎么办?
答案 0 :(得分:1)
它在Microsoft官方文档中可用,
Creates an Azure Web App using RM module
New-AzureRmWebApp
[[-ResourceGroupName] <String>]
[-Name] <String>
[[-Location] <String>]
[[-AppServicePlan] <String>]
[-ContainerImageName <String>]
[-EnableContainerContinuousDeployment]
[-AsJob]
[-GitRepositoryPath <String>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
要创建 Storage Account
New-AzureRmStorageAccount
[-ResourceGroupName] <String>
[-Name] <String>
[-SkuName] <String>
[-Location] <String>
[-Kind <String>]
[-AccessTier <String>]
[-CustomDomainName <String>]
[-UseSubDomain <Boolean>]
[-Tag <Hashtable>]
[-EnableHttpsTrafficOnly <Boolean>]
[-AssignIdentity]
[-NetworkRuleSet <PSNetworkRuleSet>]
[-AsJob]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
为 WebApp
设置存储帐户Set-AzureRmWebApp
[[-AppServicePlan] <String>]
最终代码应为
$location="West Europe"
# transform userid to lowercase since some Azure resource names don't like uppercase
$userid=$env:USERNAME.tolower()
$FuncAppName="$userid$(Get-Random)"
$rgname="$FuncAppName-rg"
$storageAccount="$($FuncAppName)stg"
$FunctionName="HttpTriggerCSharp3"
# ---------------------------------------------------------------------------------
# create the resource group
# ---------------------------------------------------------------------------------
New-AzureRmResourceGroup -Name "$rgname" -Location "$location" -force
# ---------------------------------------------------------------------------------
# create a storage account needed for the Function App
# ---------------------------------------------------------------------------------
New-AzureRmStorageAccount -ResourceGroupName "$rgname" -AccountName "$storageAccount" -Location "$location" -SkuName "Standard_LRS"
$keys = Get-AzureRmStorageAccountKey -ResourceGroupName "$rgname" -AccountName "$storageAccount"
$storageAccountConnectionString = 'DefaultEndpointsProtocol=https;AccountName=' + $storageAccount + ';AccountKey=' + $keys[0].Value
# ---------------------------------------------------------------------------------
# create the Function App
# ---------------------------------------------------------------------------------
New-AzureRmResource -ResourceGroupName "$rgname" -ResourceType "Microsoft.Web/Sites" -ResourceName "$FuncAppName" -kind "functionapp" -Location "$location" -Properties @{} -force
$AppSettings = @{'AzureWebJobsDashboard' = $storageAccountConnectionString;
'AzureWebJobsStorage' = $storageAccountConnectionString;
'FUNCTIONS_EXTENSION_VERSION' = '~1';
'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING' = $storageAccountConnectionString;
'WEBSITE_CONTENTSHARE' = $storageAccount;
}
Set-AzureRMWebApp -Name "$FuncAppName" -ResourceGroupName "$rgname" -AppSettings $AppSettings