0

我们发现我们的 AzureRM 脚本已经开始失败,请求错误下级服务失败。这迫使我们更改脚本以开始使用 AZ powershell 模块,https: //docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-1.6.0 。转换效果非常好,只是我没有找到 New-AzureWebsiteJob 的替代品。有没有其他人遇到过这个?

4

1 回答 1

1

对于New-AzureWebsiteJobcmdlet,Az 或 ARM PowerShell Cmdlet 中没有直接等效项。

你可以按照这个博客来达到你的目的,注意如果你使用的是Az powershell模块,请将ARM Powershell分别修改为Az powershell。

Az powershell 的示例代码如下:

#Resource details :
$resourceGroupName = "<Resourcegroup name>";
$webAppName = "<WebApp name>";
$Apiversion = 2015-08-01

#Function to get Publishing credentials for the WebApp :
function Get-PublishingProfileCredentials($resourceGroupName, $webAppName){

$resourceType = "Microsoft.Web/sites/config"
$resourceName = "$webAppName/publishingcredentials"
$publishingCredentials = Invoke-AzResourceAction -ResourceGroupName $resourceGroupName -ResourceType 
$resourceType -ResourceName $resourceName -Action list -ApiVersion $Apiversion -Force
   return $publishingCredentials
}

#Pulling authorization access token :
function Get-KuduApiAuthorisationHeaderValue($resourceGroupName, $webAppName){

$publishingCredentials = Get-PublishingProfileCredentials $resourceGroupName $webAppName
return ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f 
$publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword))))
}

$accessToken = Get-KuduApiAuthorisationHeaderValue $resourceGroupName $webAppname
#Generating header to create and publish the Webjob :
$Header = @{
'Content-Disposition'='attachment; attachment; filename=Copy.zip'
'Authorization'=$accessToken
        }
$apiUrl = "https://$webAppName.scm.azurewebsites.net/api/<Webjob-type>/<Webjob-name>"
$result = Invoke-RestMethod -Uri $apiUrl -Headers $Header -Method put -InFile "<Complete path of the file>\
<filename>.zip" -ContentType 'application/zip' 
于 2019-03-27T01:31:17.230 回答