Azure Powershell script检测登陆并部署ARM Template
本文简单提供了一个Azure powershell脚本,能实现如下功能
- Azure (China)账户是否已经登陆了,如果没登陆,会提示你登陆。
- 要创建的资源组是否存在,存在的话不再创建,直接部署template,不存在就先创建资源组,再部署template。
## 简单定义变量
$ResourceGroupName='myrsg'
$Location='china east'
## 检测是否已经登陆azure,如果没登陆,会跳转提示登陆。
Try
{
Get-AzureRmContext -ErrorAction Continue
}
Catch [System.Management.Automation.PSInvalidOperationException]
{
Login-AzureRmAccount -EnvironmentName Azurechinacloud
}
## define the deploy function,指定部署文件的路径。可以是远端文件,也可以是本地文件。
Function Deployment([string]$deployPath,[string]$deployParameterPath)
{
Write-Output "test the deployment"
test-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName <code>
-TemplateFile $deployPath </code>
-TemplateParameterFile $deployParameterPath
Write-Output "deploy begin"
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName <code>
-TemplateFile $deployPath </code>
-TemplateParameterFile $deployParameterPath
}
## 检测资源组是否存在,逻辑行为可定制。
## reousrceGroup的部署是增量的形式,组下的已有资源不再被重新部署。
$resourceGroup = Get-AzureRmResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue
if ( -not $ResourceGroup ) { Write-Output "Could not find resource group '$ResourceGroupName' - will create it" Write-Output "Creating resource group '$ResourceGroupName' in location '$Location'"
New-AzureRmResourceGroup -Name $resourceGroupName -Location $Location
Deployment .\Desktop\template\template\azuredeploy.json .\Desktop\template\template\azuredeploy.parameters.json
}
else {
Write-Output "Using existing resource group '$ResourceGroupName'"
Deployment .\Desktop\template\template\azuredeploy.json .\Desktop\template\template\azuredeploy.parameters.json
}
主体逻辑大致如上,你可以自己优化一下。Line 11是登陆China Azure的,登陆global Azure移除参数即可。
如果你对Azure ARM 不了解,可以参考如下,进行深入学习:
ARM template
Azure ARM template github
Azure Powershell script检测登陆并部署ARM Template的更多相关文章
- Azure Powershell使用已有Image创建ARM非托管磁盘虚拟机
生成Image映像文件,记录好Image的URL(下面URL为测试URL,具体请参考实际):ImageURL:https://hlmrgstoragen.blob.core.chinacloudapi ...
- 【Azure 微服务】Service Fabric, 使用ARM Template方式来更新SF集群的证书(Renew SF Certificate)
问题描述 因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)一文中,描述了因为证书过期而导致了SF集群不可用,并且通过命令dd-AzServiceFabricCluster ...
- Azure Powershell对ARM资源的基本操作
本分主要介绍Windows Azure Powershell对ARM资源的基本操作 1.登陆ARM模式,命令:Login-AzureRmAccount -EnvironmentName AzureCh ...
- Azure PowerShell (13) 批量设置Azure ARM Network Security Group (NSG)
<Windows Azure Platform 系列文章目录> 刚刚在帮助一个合作伙伴研究需求,他们的虚拟机全面的网络安全组(Network Security Group, NSG)会经常 ...
- PowerShell Script to Deploy Multiple VM on Azure in Parallel #azure #powershell
Since I need to deploy, start, stop and remove many virtual machines created from a common image I c ...
- Azure PowerShell (14) 批量导出Azure ASM ACL和ARM NSG配置信息
<Windows Azure Platform 系列文章目录> 最近有一个客户需求,需要批量导出Azure Classic VM的ACL (Access Control List), 还有 ...
- 通过Azure Powershell获取asm及arm虚拟机的配置信息
1.asm虚拟机可以使用类似如下Azure Powershell命令获取虚拟机的基本信息,包括发行版本,虚拟机名称及size[备注:虚拟机需要是使用平台image创建的] PS C:\Users\he ...
- Windows 上安装 Azure PowerShell及Azure PowerShell部署虚拟机
一.Azure PowerShell部署 1.使用 PowerShellGet 在 Windows 上安装 Azure PowerShell 从 Azure PowerShell 版本 6.0 开 ...
- Azure Powershell部署使用平台映像的托管Windows VM及相关问题说明
1.脚本背景信息: a.使用平台镜像(Windows Server 2016 zh-cn)部署高性能托管磁盘虚拟机 b.虚拟机默认不开启Boot诊断 c.添加三块已经创建好的数据磁盘 d.添加已创建好 ...
随机推荐
- [JDBC]ORA-01000: 超出打开游标的最大数(ORA-01000: maximum open cursors exceeded)
问题产生的原因: Java代码在执行conn.createStatement()和conn.prepareStatement()的时候,相当于在数据库中打开了一个cursor.由于oracle对打开的 ...
- BodeAbp前端介绍
BodeAbp的前端可以根据自己的喜好选型,推荐React.js.angular2.js.vue.js,后续我会以react.js为例说明BodeAbp前端的一些设计思路. BodeAbp提供的前端d ...
- [C#]SQLite执行效率优化结论
一.如要使用SQLite,可以从Visual Studio中的“程序包管理器控制台”输入以下命令完成安装: PM> Install-Package System.Data.SQLite.Core ...
- Individual Project 1 总结
题目: http://www.cnblogs.com/jiel/p/3978727.html 1. 估计时间: ① 遍历目录找到所有文本文件 3天 ② 编写统计词频的函数 排序的函数 并输出到文件 2 ...
- 单工程搭建springmvc+spring+mybatis(maven,idea)
单工程搭建springmvc+spring+mybatis(maven,idea) 1.pom.xml <properties> <project.build.sourceEncod ...
- Redis交互编程语言及客户端
Redis Desktop Manager https://redisdesktop.com/download Redis Clients https://redis.io/clients/ ...
- 关于splice()方法,slice() 、split()方法讲解,reverse()方法、replace()方法
1.slice() 方法可从已有的数组中返回选定的元素. 语法 arrayObject.slice(start,end) 参数 描述 start 必需.规定从何处开始选取.如果是负数,那么它规定从数组 ...
- VMMAP的简单使用
1. dotnet.exe 进程占用内存非常疯狂.. 开发同事 提供了一个工具进行简单分析 vmmap.exe 执行了 Ctrl+E 之后 发现将 heap 和managed heap 的内容放到了p ...
- ionic2添加 android平台出现的问题
nodejs版本不宜过高 cordova版本不宜过高 此情况应采取 cordova platform add android --nofetch
- 数字证书签发,授权等相关以及https建立通信过程
一直以来都对数字证书的签发,以及信任等事情一知半解.总算有个闲适的周末来总结和深入一下相关的知识. CA: CA(Certificate Authority)是证书的签发机构,它是负责管理和签发证书的 ...