Reputation: 1678
I wrote this Azure PowerShell
script
$DataFactoryName = "BI-Dashboard-DataFactory-2"
$ResourceGroupName = "BI-Dashboard-ResourceGroup-2"
$ResourceGroup = Get-AzResourceGroup -Name $ResourceGroupName
# Write-Output $DataFactory.DataFactoryName
if(-not $ResourceGroup)
{
$ResourceGroup= New-AzResourceGroup $ResourceGroupName -location 'westeurope'
Write-Output " Resource Group Created Successfully "
}
else
{
# Resource Group Already Exists
Write-Output "Resource Group Exists"
}
$DataFactory = Get-AzDataFactoryV2 -Name $DataFactoryName -ResourceGroupName $ResourceGroup.ResourceGroupName
if (-not $DataFactory)
{
$DataFactory = Set-AzDataFactoryV2 -ResourceGroupName $ResourceGroup.ResourceGroupName -Location $ResourceGroup.Location -Name $DataFactoryName
Write-Output " Data Factory Created Successfully "
}
else
{
Write-Output "Data Factory {0} Already Exists" -f $DataFactory.DataFactoryName
}
some time ago and if Resource
or Data Factory
does not exist it didn't throw any exception, it simply executed if block.
I have created a new subscription and executing the same PowerShell
script against new subscription and now receives this exception in red color as well as execution of if block. I need to know whether something is changed in Azure Resource Manager
when its accepting this PowerShell
request to display error message or this is not an issue.
Upvotes: 0
Views: 2492
Reputation: 12768
You will receive this error message "Get-AzDataFactoryV2 : HTTP Status Code: NotFound", when the resource doesn't exists in the resource group.
The script first looks for the resource group exists or not, then it will check for the data factory exists in the resource group or not.
If the resource exists gives the results, else it throws the error message.
Example: In my resource group named chpradeep, I have a data factory name "chepra".
Case1: (Success) If I run the below cmdlet gives the results because the data factory named chepra exists in the resource group.
Get-AzDataFactoryV2 -ResourceGroupName "chpradeep" -Name chepra
Case2: (Error) If I run the below cmdlet gives the error message because the data factory named alpha doesn't exists in the resource group.
Get-AzDataFactoryV2 -ResourceGroupName "chpradeep" -Name alpha
Hope this helps.
Upvotes: 1