"The term '***' is not recognized as the name of a cmdlet" error thrown in Azure Powershell step in Azure DevOps Pipeline - azure

I have an Azure Powershell step in my release pipeline that calls the Invoke-RestMethod cmdlet to make a call to the kudu API.
At the point of creating the step is selected my Azure Subscription from the list of available subscriptions and it uses this to authenticate.
I was able to run the step successfully at first, getting the following output in the console log:
However, for every subsequent release now I am receiving the error ##[error]The term '***' is not recognized as the name of a cmdlet, function, script file, or operable program. with the following output:
I haven't changed the powershell that the step actually runs. Could there be an issue with the way the release pipeline is authenticating and selecting the subscription? I see in the output that the TenantId is shown as ***, which is what the error message is complaining about, could that be the source of it?

It looks like a problem in your script. *** is used to mask secret variables, so your script is probably doing something where it's trying to run the contents of a variable. Maybe something like &$TenantId.

Related

Automating Azure Sentinel deployment with Powershell error

https://github.com/javiersoriano/sentinel-all-in-one/blob/master/README.md
This is basically what I am trying to do. I am trying to automate the process of deploying a SIEM, Azure Sentinel to our customers' environment to save time, but I get these errors and would not process. I got the JSON file and the ps1 file in the same folder.
Error 1
I get these messages in the picture above. Then it proceeds to the next step which wants me to log in with my Azure account. I don't think I logged in but it proceeds without asking when I click enter.
Then I get these errors below:
Error 2

Azure Batch Service cannot find Az.DataFactory cmdlets when run as a Custom Activity

I am attempting to automate the activation of SSIS Integration Runtimes by running a pipeline containing a Custom Activity in Azure Data Factory.
I have set the Batch Service up with a linked storage account and have successfully started to run a .ps1 file in the linked storage account. I know it find the file OK because I can see a node is running and I get an adfjob set of logs in my storage account.
The Powershell script is a simple one liner:
Start-AzDataFactoryV2IntegrationRuntime -Name SSIS -ResourceGroupName <RG Name> -DataFactoryName <ADF Name> -Force
However, the output log file says that it cannot find the cmdlet:
The term 'Start-AzDataFactoryV2IntegrationRuntime' is not recognized
as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
So I take it from the log that Powershell is available on the node but the Az module is not. I find this extremely surprising given it's an Azure Batch Service node. I've tried adding an Install-Module Az ... to the start of this script, the result is it appears to be hanging and I don't know how to track if it is doing anything or not, but in any case I cancelled after 8mins because I'm pretty sure it would have installed by then.
So I am therefore wondering where the Az module should be installed and how to go about doing so?
You could install the Az module with your Batch Start task in order for your task to use it.
By associating a start task with a pool, you can prepare the operating environment of its nodes. For example, you can perform actions such as installing the applications that your tasks run, or starting background processes.

Request timing out when exporting Azure resource group in powershell

I want to export an ARM template for a resource group in Windows Azure. I'm using the Azure Powershell module.
Whenever I try to export the resource group using Export-AzResourceGroup, the cmdlet fails with the following error:
Export-AzResourceGroup : Operation failed because a request timed out.
I have inspected the web traffic with Fiddler and I can see that the actual HTTP call to Azure is completing successfully, it's just taking a long time. So it's not a matter of e.g. extending the timeout on the ServicePointManager.
Is there any solution or work-around to stop this cmdlet timing out?
This issue maybe occurring due to a previous version of Az powershell module. Please update your Az module to the latest version and try again.
Also make sure you have the write permissions in the directory you are trying to create the json file.
Meanwhile, you can create the template from the portal just to check if the json file is getting created successfully:
https://learn.microsoft.com/en-us/azure/azure-resource-manager/export-template-portal#export-template-from-a-resource-group

VSTS Build Succeeded even ARM Template was invalid

Am working on Azure Resource Manager Templates(ARM Templates) and VSTS CI&CD. With the help of ARM Templates, I want to deploy AKS (Azure kubernete Service). So before going to deploy, I need to validate my ARM Template in the CI-Build by applying a PowerShell task. But here, at the time of validating my ARM Template “It’s not stopping CI-Build even when the validation fails”. Its giving output as “Validation Completed” as shown in the below picture . Is there any solution to resolve this issue, i.e. I wanted to stop my CI-Build running if any validation fails.
Not sure how does your powershell script look like. But according to the screenshot, the powershell script is executed successfully without any error code return. You can update your powershell script to check the validate result and set the exit code to "1" if the result is "InvalidTemplate". This will make the powershell task fail when the template is valid.
Looks like the resource is defined multiple times in the template. You can remove it and its always a good practice from the PowerShell script to use Test-AzureRmResourceGroupDeployment and validate if the template is valid and has obtained all its parameters and then deploy using New-AzureRmResourceGroupDeployment
Like Eddie said you can try this inside a try{} catch block and return an exception or an exit code to make the VSTS Build pipeline fail, if the script fails.

What is a proper endpoint format for creating an Event Grid subscription

I have an Azure Function executed by Event Grid trigger. The function is debugged and functioning as designed. I was able to successfully create a subscription to an Event Grid topic using UI in the Azure Portal (click Add Event Grid subscription and complete the on-screen form).
The problem is I cannot get the endpoint format correct when attempting to use the CLI (Cloud Shell logged in as Administrator) to create a subscription. The basic template I'm using is
az eventgrid event-subscription create --resource-group $resourceGroup
--topic-name $topicName
--included-event-types $includedEventTypes
--name $eventSubscriptionName
--endpoint https://XXX.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName=FunctionName&code=ABC123
I've tried copying the auto-populated endpoint, including its code parameter, from the UI. It works in the UI but not from CLI. When I run the above script using the endpoint and code provided in the portal, I get the following
The term 'code=<XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX> is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
If I omit the code, I get a message indicating the subscription failed because it couldn't validate the endpoint.
If I attempt to use the endpoint, in the form usually seen for function endpoints, https://XXX.azurewebsites.net/FunctionName, I also get complaints about validation.
What is the proper format for the endpoint when creating a subscription from the CLI in Cloud Shell? Do I include the code parameter or not? Where do I get the proper code?
Using:
Microsoft.NET.Sdk.Functions 1.0.19
Microsoft.Azure.EventGrid 1.4.0
Microsoft.Azure.WebJobs.Extensions.EventGrid 1.0.0
Try to wrap your function endpoint with quote sign, & seems a reserved sign in CLi syntax hence your parameter code is cut from the url.

Resources