I want to run powershell scripts to create users and usergroups in Azure AD . Is it possible to call ps scripts in ARM Template?
-
1Maybe you could use Azure Custom Script Extension.Shui shengbao– Shui shengbao2017-12-14 06:56:49 +00:00Commented Dec 14, 2017 at 6:56
-
But that is for running script on Azure VM. I need to run a powershell script to create users.Paritosh Sharma– Paritosh Sharma2017-12-14 07:12:52 +00:00Commented Dec 14, 2017 at 7:12
-
Yes, when executing script, it need a host. So, Azure ARM template could not do this directly.Shui shengbao– Shui shengbao2017-12-14 07:14:54 +00:00Commented Dec 14, 2017 at 7:14
-
You need install Azure AD Power Shell on your VM, then you could execute your scripts.Shui shengbao– Shui shengbao2017-12-14 07:15:50 +00:00Commented Dec 14, 2017 at 7:15
-
Okay.So that is only possible for Windows VM or can be done for Linux VM also?Paritosh Sharma– Paritosh Sharma2017-12-14 07:20:32 +00:00Commented Dec 14, 2017 at 7:20
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.
Comments
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.