Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i run powershell scripts through ARM Template?

I want to run powershell scripts to create users and usergroups in Azure AD . Is it possible to call ps scripts in ARM Template?

like image 669
Paritosh Sharma Avatar asked Jun 15 '26 18:06

Paritosh Sharma


2 Answers

Update: Now it is possible to do some operations with a new feature (still in Preview)

https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-script-template

Use deployment scripts in templates (Preview)

Learn how to use deployment scripts in Azure Resource templates. With a new resource type called Microsoft.Resources/deploymentScripts, users can execute deployment scripts in template deployments and review execution results. These scripts can be used for performing custom steps such as:

  • add users to a directory
  • create an app registration
  • perform data plane operations, for example, copy blobs or seed database
  • look up and validate a license key
  • create a self-signed certificate
  • create an object in Azure AD
  • look up IP Address blocks from custom system

The benefits of deployment script:

  • Easy to code, use, and debug. You can develop deployment scripts in your favorite development environments. The scripts can be embedded in templates or in external script files.
  • You can specify the script language and platform. Currently, only Azure PowerShell deployment scripts on the Linux environment are supported.
  • Allow specifying the identities that are used to execute the scripts. Currently, only * * Azure user-assigned managed identity is supported.
  • Allow passing command-line arguments to the script.
  • Can specify script outputs and pass them back to the deployment.

Remember that ARM templates should be idempotent. You should write code that can be executed multiple times, even on environments where your code was already executed. For example, if you are going to configure a setting, or create a resource, your powershell should probably check if the resource is already in place and properly configured.

like image 98
Carlos Garcia Avatar answered Jun 18 '26 00:06

Carlos Garcia


No, Azure ARM could not execute scripts directly. Executing scripts need host, Azure template does not provide such host.

One solution, you could select Azure Custom Script Extension.

The Custom Script Extension downloads and executes scripts on Azure virtual machines.

like image 21
Shui shengbao Avatar answered Jun 18 '26 00:06

Shui shengbao