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.添加已创建好 ...
随机推荐
- 1kb的前端HTML模板解析引擎,不限于嵌套、循环、函数你能想到的解析方式
传送门:https://github.com/xiangyuecn/BuildHTML copy之前说点什么 html做点小功能(什么都没有),如果是要手动生成html这种操作,容易把代码搞得乱七八糟 ...
- 运行supervisord -c /etc/supervisor/supervisord.conf 出错,解决办法
坑都让我踩了...... 1 supervisord -c /etc/supervisor/supervisord.conf 什么意思? 答:手动启动:supervisord 具体详见 ...
- openssl版本升级操作记录
需要部署nginx的https环境,之前是yum安装的openssl,版本比较低,如下: [root@nginx ~]# yum install -y pcre pcre-devel openssl ...
- NTP系统时间同步-操作记录
在初始化一台linux服务器后,发现这台服务器的时间不对[root@dev ~]# date2016年 10月 11日 星期二 07:04:34 CST Linux时钟分为系统时钟 (System C ...
- apacheTomcat
Window+R ------>cmd || Window PowerShell apacheTomcat\bin> ./startup.sh
- 微信扫描 安卓和ios 不会
wx.ready(function(){ $('#scan').click(function(){ wx.scanQRCode({ needResult: 1, // 默认为0,扫描结果由微信处理,1 ...
- 个人作业Week1
一.<构建之法>提问 1.需求是什么?需求的规范需要明确吗? 2.一个人开发效率非常高,多人开发,个人效率随团队人数上升而直线下降,我们一般需要将大项目拆为小项目,使协作耦合产生的效率负影 ...
- Scrum Meeting 5
第五次会议 No_00:工作情况 No_01:任务说明 待完成 已完成 No_10:燃尽图 No_11:照片记录 待更新 No_100:代码/文档签入记录 No_101:出席表 ...
- <<梦断代码>>阅读笔记一
没有想象中的枯燥,甚至有些有趣.这就是我对<梦断代码>这一本书的第一印象.而且,作为一本面向程序员的书籍,作者很有意义地从第0章开始,那我也从第0章开始说.这第一次读书笔记是针对0~2 章 ...
- Git学习笔记 第二章
文件相关操作 修改readme.txt文件,执行 git status 命令查看当前仓库状态 git status 位于分支 master 尚未暂存以备提交的变更: (使用 "git add ...