Paritosh Sharma
Paritosh Sharma

Reputation: 43

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?

Upvotes: 2

Views: 10889

Answers (2)

Carlos Garcia
Carlos Garcia

Reputation: 2970

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.

Upvotes: 11

Shui shengbao
Shui shengbao

Reputation: 19195

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.

Upvotes: 4

Related Questions