How to run AzureRM script via azure devops pipeline - azure

I am attempting to run an azureRM script via a devops pipeline.
I have tried all the possible powershell tasks, however I am always met with the following error:
New-AzureRmResource : The term 'New-AzureRmResource' is not recognized as a name of a cmdlet, function, script file, or executable program.
The script is designed to add a VNET to an app service.
I am aware that AzureRM is outdated, however there is no way to do cross-regional VNet integration via Az or the az cli.
How can I run an AzureRm script via a devops pipeline?

I assume you use Microsoft Hosted Agents
Multiple ways:
Invoke-RestMethod - All commands are accessible as API endpoints.
Install-Module - Just Install AzureRM.
Use AzurePowerShell#3 task version - Easiest solution - See docs, The newer #4 and #5 versions do not support AzureRM.

Because Az PowerShell modules now have all the capabilities of AzureRM PowerShell modules and more, we'll retire AzureRM PowerShell modules on 29 February 2024. So you can try to use Az.Resources module instead.
For the changes between AzureRm and Az, please view this document(Az.Resources (previously AzureRM.Resources)).
In addition, agree with Repcak. You can use AzurePowerShell#3 task or earlier, because these versions of task support AzureRm modules.

Related

Job Suspended Run Login-AzureRmAccount to login using Azure AutomationAccounts System Managed Identity

I am trying to shutdown the VM using Azure Automation Account System Managed identity option.
However I am ending up with below error.
As per the other articles it is mentioned to upgrade the module Update-ModulesInAutomationToLatestVersion but I could not update due to below error. I am not sure what is the issue in the script. Same script works with AzureRunAsConnection option without issues ( script ).I even checked with simple login with System Managed Identity it successfully login and fetches the resource group names.
I have tested the above shared script in my automation account. Below are
the couple of observations:
You need to use Connect-AzureRMAccount -Identity cmdlet instead of 'connect-AzAccount` to connect to your subscription because the rest of the script that you have written using Azure RM cmdlets.
If we use AzureRM cmdlets in your run book script the job is getting suspended stating that Azure RM is going to retired and suggesting us to use Az Module in your workflow.
You can refer to this documentation on how to migrate your PowerShell scripts automatically from AzureRM to AZ modules.
If you want to perform start/stop on your virtual Machines you can leverage the Azure Automation start/stop during the off hours feature.
According to the MICROSOFT DOCUMENTATION and looking at your script the Azure Rm module is not supported and it has been updated to the latest version of Az module.
For more information please refer the below links:-
MICROSOFT DOCUMENT|Using a system-assigned managed identity for an Azure Automation account & Troubleshoot runbook issue.

AzureRm Add-AzureCertificate equivalent in Az

Ahead of the deprecation of the AzureRM powershell cmdlets later this year I am updating some of our infrastructure scripts to use the Az powershell cmdlets rather than AzureRM.
One of our scripts uploads SSL certificates to Azure Cloud Service(Classic) resources using Add-AzureCertificate:
Add-AzCertificate -ServiceName $serviceName -CertToDeploy $certObject
where $certObject is a X509Certificate2 object.
What is the equivalent cmdlet in the Az module? Add-AzCertificate does not exist.
On the Cloud Service documentation page where it details configuring SSL, only certificate upload via the Azure portal is shown.
As the comment from #Alex AIT, before call the AzureRM commands, you can run Enable-AzureRmAlias cmdlet which enables a compatibility mode through aliases, to allow you to use existing scripts with minimal modification while working towards a full migration to Az. For more information, you could refer to Migrate existing scripts to Az.
Also, to call Azure Cloud Service(Classic) resources, you still need Azure modules. View this example- Az / AzureRM / Legacy Azure Powershell Conflicts.

How to implement Update-AzSqlServerVulnerabilityAssessmentSetting using AzureRM

I have an Az script that sets up Advanced Data Security for my Azure SQL Databases/Servers.
Unfortunately, Az cannot run in Azure Devops, so I translated the script to AzureRM. The script leaves Advanced Data Security in a "Partially Configured" state, due to the Azure SQL Server's VULNERABILITY ASSESSMENT SETTINGS not being set.
What is the AzureRM equivalent of Update-AzSqlServerVulnerabilityAssessmentSetting
I tried
Update-AzSqlServerVulnerabilityAssessmentSetting
to:
Update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings
However, only the database gets configured and this leave the Server unconfigured.
They are not an equivalent, the AzureRm module was deprecated and will not be updated.
Unfortunately, Az cannot run in Azure Devops, so I translated the script to AzureRM.
As I know, the Task version with 4.*(preview) supports Az module. I tried it here.
If you want to AzureRm module to update Azure SQL Vulnerability Assessment Setting, you just can use command "update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings" to configure all database in one server, AzureRM does not provide command to enable customers to directly configure Azure SQL server. For more details, please refer to the blog.
Get-AzureRmSqlDatabase -ResourceGroupName $params.rgname -ServerName $params.serverName`
| where {$_.DatabaseName -ne "master"} `
| Update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings `
-RecurringScansInterval Weekly `
-NotificationEmail $scanNotificationEmail `
-EmailAdmins $true"

How can I run Azure's Get-AzureServiceAntimalwareConfig cmdlet equivalent in the new Azure Cloud Power Shell 'Az'

In Azure Power Shell within the Azure cmdlet module there is a cmdlet called "Get-AzureServiceAntimalwareConfig". I want to run the equivalent cmdlet but from the new PowerShell Az cmdlet module. How can I find the equivalent cmdlet for 'Az'? Do I need to install a cmdlet module that isn't already installed by default? I'm using Azure Cloud Shell.
It seems there is no equivalent command of Get-AzureServiceAntimalwareConfig in Az powershell module.
The command is used to get the antimalware configuration and monitoring configuration details associated with the Microsoft Antimalware extension for a cloud service. Cloud service is a classic(ASM) service, but the Az powershell module is for ARM.

Azure DevOps Pipelines Azure PowerShell task: The variable '$PSEdition' cannot be retrieved because it has not been set

Receiving an error in the Azure DevOps Pipelines Azure PowerShell task:
##[error]The variable '$PSEdition' cannot be retrieved because it has not been set.
The latest AzureRM modules were just installed (6.11.0 at the time of this post).
The AzureRM 6.11.0 module is looking for the $PSVersionTable.PSEdition property which is available in PowerShell 5.1 and greater. Download and install from here: https://www.microsoft.com/en-us/download/details.aspx?id=54616

Resources