我有一个powershell
,它将一些工件部署到azure。我向用户询问以下定义模板参数文件的值。
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"
}
答案 0 :(得分:1)
获取部署的详细信息:
Get-AzureDeployment
[-ServiceName] <String>
[[-Slot] <String>]
[-Profile <AzureSMProfile>]
[-InformationAction <ActionPreference>]
[-InformationVariable <String>]
[<CommonParameters>]
Documentation中的更多细节或插入您的Powershell:
get-help Get-AzureDeployment -ShowWindow