我可以通过 ARM 模板 运行 powershell 脚本吗?
Can i run powershell scripts through ARM Template?
我想运行 powershell 脚本在 Azure AD 中创建用户和 usergroups。是否可以在 ARM 模板中调用 ps 脚本?
不,Azure ARM 无法直接执行脚本。执行脚本需要host,Azure模板没有提供这样的host。
一个解决方案,你可以 select Azure Custom Script Extension。
自定义脚本扩展在 Azure 虚拟机上下载并执行脚本。
更新:
现在可以使用新功能进行一些操作(仍在预览中)
https://docs.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.
请记住,ARM 模板应该是幂等的。您应该编写可以多次执行的代码,即使在您的代码已被执行的环境中也是如此。
例如,如果您要配置设置或创建资源,您的 powershell 可能应该检查资源是否已经到位并正确配置。
我想运行 powershell 脚本在 Azure AD 中创建用户和 usergroups。是否可以在 ARM 模板中调用 ps 脚本?
不,Azure ARM 无法直接执行脚本。执行脚本需要host,Azure模板没有提供这样的host。
一个解决方案,你可以 select Azure Custom Script Extension。
自定义脚本扩展在 Azure 虚拟机上下载并执行脚本。
更新: 现在可以使用新功能进行一些操作(仍在预览中)
https://docs.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.
请记住,ARM 模板应该是幂等的。您应该编写可以多次执行的代码,即使在您的代码已被执行的环境中也是如此。 例如,如果您要配置设置或创建资源,您的 powershell 可能应该检查资源是否已经到位并正确配置。