Cannot find Azure Data Factory - azure

I was executing this command:
$obj = Get-AzDataFactory -ResourceGroupName $rgName -Name $adfName
I get this error but the ADF exists.
HTTP Status Code: NotFound Error Code: ResourceNotFound
Error Message: The Resource 'Microsoft.DataFactory/dataFactories/*******'
under resource group 'DEV*****RG' was not found.
When this command runs, the ADF is listed!
Get-AzResource -ResourceGroupName "DEV*****RG"

'Get-AzDataFactoryV2' is the correct command

Related

API Import in APIM using Azure Pipeline

I am trying to import API using swagger.json file using Azure Pipeline. I have added a Azure CLI Task Version 2. Selected Script Type as Powershell Core.
In the inline script I have used below commands
$apiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName
$api = Get-AzApiManagementApi -Context $apiMgmtContext -Name $ApiName
The first one is working fine. But the second line of code is throwing error.
Below is the error I get:
I have searched this error Status Code : CloseError But no solid information on the same. I tried to Install few powershell modules for Azure Api , still it gives the same error.
I have tried with the below mentioned Azure APIM PowerShell Commands to get the API details from the Azure APIM Instance and got expected results:
$ApimResource = New-AzApiManagement -Name "pravusapim1205" -ResourceGroupName "pravutestrg" -Location "West US" -Organization "Contoso" -AdminEmail "admin#contoso.com"
$ApimResourceDetails = Get-AzApiManagement -Name "pravusapim1205" -ResourceGroupName "pravutestrg"
$ApimResourceDetails
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName "pravutestrg" -ServiceName "pravusapim1205"
$ApiName = "Echo API"
$api = Get-AzApiManagementApi -Context $apiMgmtContext -Name $ApiName
$api
Output:
Reference: GitHub Doc on APIM PS Commands.

Set Azure Automation Status as failed on Invoke-AzVMRunCommand error to trigger an alert

I have this command running inside an automation runbook. Sometimes if the VM is stopped the command gives error. Based on this error I want the Status of automation runbook be 'Failed' instead of completed. But the runbook is giving 'Completed' status. Because of this I am unable to trigger an alert using Azure Monitor(which checks for status value). How to set the runbook status to 'Failed' on such errors in the runbook?
$result=Invoke-AzVMRunCommand -ResourceGroupName $VMResourceGroupName -VMName $VMname -ScriptPath ScriptToRun.ps1 -CommandId 'RunPowerShellScript'
if ($result.value.Message -like '*error*')
{
throw $result.value.Message
}
You can refer to THIS similar question. The answer should hold good for your case as well.
Your code is wrong. This is the correct one. The throw will make the runbook fail. The code in question is applicable when running it inside a VM(not through automation runbook)
$result=Invoke-AzVMRunCommand -ResourceGroupName $VMResourceGroupName -VMName $VMname -ScriptPath ScriptToRun.ps1 -CommandId 'RunPowerShellScript'
if(!$result)
{
throw "Error Occured"
}
else
{
Write-Output "Succeeded"
}

Not Able to add a custom script extension for Linux vm

I have a linux Cent OS vm and am trying to add a custom script to it. If i do it manually from the portal i am able to install the custom script extension for linux. But i am not able to install the custom script via powershell code that i added below. Need some help on it. I am storing the custom script file in a storage account and calling it from there when installing the custom script extension on Linux.
Error i get is : Enable failed: processing file downloads failed: failed to download file[0]: failed to download file: unexpected status code: actual=404 expected=200
if($vmname.OSType -eq "Linux"){
$resourcegroup=$vmname.ResourceGroupName
$location=$vmname.Location
$vm=$vmname.Name
$TheURI = "https://storageaccount.blob.core.windows.net/container/cstmscript.sh"
$ScriptSettings = #{"fileUris" = #($TheURI); "commandToExecute" = "sh cstmscript.sh";}
Set-AzVMExtension -ResourceGroupName $resourcegroup -VMName $vm -Name "Custom Script" -Publisher "Microsoft.Azure.Extensions" -TypeHandlerVersion 2.0 -ExtensionType "CustomScript" -Location $location -Settings $ScriptSettings
}
Cant use Set-AzVMCustomScriptExtension as that's for only Windows VM's
Thanks Satya It did work Btw . I needed to add the access keys.
here is the code
if($vmname.OSType -eq "Linux"){
$resourcegroup=$vmname.ResourceGroupName
$location=$vmname.Location
$vm=$vmname.Name
$TheURI = "https://storage.blob.core.windows.net/container/cstmscript.sh"
$ScriptSettings = #{"fileUris" = #($TheURI); "commandToExecute" = " sh cstmscript.sh";}
$ProtectedSettings = #{"storageAccountName"="storage";"storageAccountKey" = ""};
Set-AzVMExtension -ResourceGroupName $resourcegroup -VMName $vm -Name "Custom Script" -Publisher "Microsoft.Azure.Extensions" -TypeHandlerVersion 2.0 -ExtensionType "CustomScript" -Location $location -Settings $ScriptSettings -ProtectedSettings $ProtectedSettings
}
I had tried hitting the above the url
https://storageaccount.blob.core.windows.net/container/cstmscript.sh
Which is more or less 404 error as encountered below :
Enable failed: processing file downloads failed: failed to download file[0]: failed to download file: unexpected status code: actual=404 expected=200
Looks like you re not able to access the cstmsscript.sh & encountering a 404 - you will have to host the file anonymously accessible or alternatively use means to grant access ( like SAS )

Enabling an azure metric alert V2

i am working on azure to monitor appservices and while a Continous deployments i am trying to build an automation task to disable/enable alert during deployments
For disabling alerts it is working
Get-AzMetricAlertRuleV2 -ResourceGroupName "<resource group name>" -Name "<alert name>" | Add-AzMetricAlertRuleV2 -DisableRule
For enabling the alerts after the deployments
Get-AzMetricAlertRuleV2 -ResourceGroupName "<resource group name>" -Name "<alert name>" | Add-AzMetricAlertRuleV2 -TargetResourceRegion "westeurope"
I get the following error:
Add-AzMetricAlertRuleV2: Exception type: ErrorResponseException, Message: Alert update failed. Updating from StaticThresholdCriteria and odata.type SingleResourceMultipleMetricCriteria to StaticThresholdCriteria and odata.type MultipleResourceMultipleMetricCriteria is not supported. Activity ID: ec818831-0516-44a7-92ff-cbddaa82b634., Code: BadRequest, Status code:BadRequest, Reason phrase: BadRequest
You should not change the region by passing -TargetResourceRegion param while enabling. Add-AzMetricAlertRuleV2 is trying add a new rule thinking that it's a new rule and failing because of the shown error message (Updating from StaticThresholdCriteria and odata.type SingleResourceMultipleMetricCriteria to StaticThresholdCriteria and odata.type MultipleResourceMultipleMetricCriteria is not supported). So just enable by without passing any other params like below.
Get-AzMetricAlertRuleV2 -ResourceGroupName "<resource group name>" -Name "<alert name>" | Add-AzMetricAlertRuleV2

Azure App Service - Set-AzWebApp : Operation returned an invalid status code 'Conflict'

I am trying to run Set-AzWebApp command to set web application properties
Set-AzWebApp -AppSettings $settings -ResourceGroupName $resourceGroupName -Name $appServiceName
$settings is a Hashtable.
I get this message back with no additional details
Set-AzWebApp : Operation returned an invalid status code 'Conflict'
Any ideas?
Solved: As it turns out I had a space that crept into my keyname within the $settings hashtable. This cause Azure app service to throw a 409 Conflict
I also encountered this issue when creating an Azure App Service Plan using Azure Powershell.
When I run the command below:
New-AzAppServicePlan -ResourceGroupName 'MyResourceGroup' -Name 'MyServicePlan' -Location 'northeurope' -Linux -Tier 'Premium V2' -NumberofWorkers 2 -WorkerSize Medium
I get the error:
New-AzAppServicePlan: Operation returned an invalid status code 'Conflict'
Here's how I solved it:
The issue was that I was specifying the Tier as 'Premium V2' instead of 'PremiumV2'. That is there should be no space between the word Premium and V2. They should be together.
So this worked for me after then:
New-AzAppServicePlan -ResourceGroupName 'MyResourceGroup' -Name 'MyServicePlan' -Location 'northeurope' -Linux -Tier 'PremiumV2' -NumberofWorkers 2 -WorkerSize Medium

Resources