检查部署是否成功PowerShell

问题描述 投票:0回答:1

我有一个powershell,它将一些文物部署到天蓝色。我向用户询问以下定义模板参数文件的值。

1. functionapp名称:$functionAppName 2.功能应用服务计划:$functionApp_appServicePlanName 3.事件中心命名空间名称:$eventHubNamespaceName 4.存储帐户名称:$storageAccountName 5.事件中心命名空间名称:$eventHubNamespaceName

我需要测试是否在门户中成功创建了资源。为此,我使用下面的脚本来检查它是否创建。

如果它被创建,那么脚本可以继续。

如果不是,我想提示用户再次输入该失败资源的值并重新创建它。

我该怎么做 ?

Write-Host -ForegroundColor Green "Enter below values for deployment"
Write-Host -ForegroundColor Green 'Enter Function App name: ' -NoNewline
$functionAppName = Read-Host
Start-Sleep -Milliseconds 1000
Write-Host -ForegroundColor Green 'Enter Function App Service plan name: ' -NoNewline
$functionApp_appServicePlanName = Read-Host
Start-Sleep -Milliseconds 1000
while ($true) {
    Write-Host -ForegroundColor Green 'Enter Event Hub Namespace name: ' -NoNewline
    $eventHubNamespaceName = Read-Host
    Start-Sleep -Milliseconds 1000
    Write-Host -ForegroundColor Yellow "Checking whether the entered name for Event Hub Namespace is available"
    $availability = Test-AzureRmEventHubName -Namespace $eventHubNamespaceName | Select-Object -ExpandProperty NameAvailable
    if ($availability -eq $true) {
        Write-Host -ForegroundColor Green "Entered Event Hub Namespace name is available"
        break
    }
    Write-Host "Enter valid Event Hub Namespace name"
}
while ($true) {
    Write-Host -ForegroundColor Green 'Enter Storage account name: ' -NoNewline
    $storageAccountName = Read-Host 
    Start-Sleep -Milliseconds 1000
    Write-Host -ForegroundColor Yellow "Checking whether the entered name for Storage account is available"
    $availability = Get-AzureRmStorageAccountNameAvailability -Name $storageAccountName | Select-Object -ExpandProperty NameAvailable
    if ($availability -eq $true ) {
        Write-Host -ForegroundColor Green "Entered Storage account name is available"
        break
    }
    Write-Host "Enter valid Storage account name"
}
Write-Host -ForegroundColor Green 'Enter Event Hub name: ' -NoNewline
$eventHubName = Read-Host
New-AzureRmResourceGroupDeployment -functionAppName $functionAppName -functionApp_appServicePlanName $functionApp_appServicePlanName -eventHubNamespaceName $eventHubNamespaceName -storageAccountName $storageAccountName -eventHubName $eventHubName -ResourceGroupName $resourceGroupName ` -TemplateFile azuredeploy.json ` -TemplateParameterFile azuredeploy.parameters.json
if(Get-AzureRmWebApp -ResourceGroupName $resourceGroupName -Name $functionAppName | Select-Object -ExpandProperty SiteName -ErrorAction SilentlyContinue)
{
    "Found"
}
else {
    "Not Found"
}
powershell azure azure-powershell cmdlets arm-template
1个回答
1
投票

获取部署的详细信息:

Get-AzureDeployment
   [-ServiceName] <String>
   [[-Slot] <String>]
   [-Profile <AzureSMProfile>]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [<CommonParameters>]

更多详情在Documentation或插入你的Powershell:

get-help Get-AzureDeployment -ShowWindow
© www.soinside.com 2019 - 2024. All rights reserved.