Reputation: 4199
I have a powershell
which deploys some artifacts to azure. I ask the user for the below values which are defined the template parameter file.
1. functionapp Name: $functionAppName
2. Function App Service Plan: $functionApp_appServicePlanName
3. Event Hub Namespace Name: $eventHubNamespaceName
4. Storage Account Name: $storageAccountName
5. Event Hub Namespace name: $eventHubNamespaceName
I need to test whether the resources are successfully getting created in the portal. For that i have used the below script to check if its created or not.
if its created, its fine the script can continue.
if its not, I want to prompt the user to enter a value for that failed resource again and recreate it.
How do I do it ?
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"
}
Upvotes: 0
Views: 164
Reputation: 229
Gets details of a deployment:
Get-AzureDeployment
[-ServiceName] <String>
[[-Slot] <String>]
[-Profile <AzureSMProfile>]
[-InformationAction <ActionPreference>]
[-InformationVariable <String>]
[<CommonParameters>]
more Details in the Documentation or insert into your Powershell:
get-help Get-AzureDeployment -ShowWindow
Upvotes: 1