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.添加已创建好 ...
随机推荐
- [UWP 自定义控件]了解模板化控件(6):使用附加属性
1. 基本需求 之前的ContentView2添加了PointerOver等效果,和TextBox等本来就有Header的控件放在一起反而变得鹤立鸡群. 为了解决这个问题,这次把ContentView ...
- [T-ARA][ORGR]
歌词来源:http://music.163.com/#/song?id=29343993 作曲 : 4번타자/에스킴 [作曲 : 4p/beon-Ta-c/ja-/e-seu-Kim] 作词 : 4번 ...
- GlusterFS分布式存储集群部署记录-相关补充
接着上一篇Centos7下GlusterFS分布式存储集群环境部署记录文档,继续做一些补充记录,希望能加深对GlusterFS存储操作的理解和熟悉度. ======================== ...
- Beta项目展示
Team C# 一.团队成员简介 杜正远,队长. 博客地址:http://www.cnblogs.com/kevindu/ 崔强,全职PM. 博客地址:http://www.cnblogs.com/m ...
- linux内核分析第五次实验
给MenuOS增加time和time-asm命令 上周是从用户态的观点来理解系统调用,这周从内核态出发研究系统调用,通过跟踪调试,首先把上周的两个命令加到MenuOS中: rm menu -rf 强制 ...
- 20135323符运锦期中总结----Linux系统的理解及学习心得
一.网易云课堂 1.各章节总结 第一周:计算机是如何工作的http://www.cnblogs.com/20135323fuyunjin/p/5222787.html 第二周:操作系统是如何工作的ht ...
- 爬虫时http错误提示
在爬虫,请求网站的时候,有时候出现域名报错,所出现的代码所对应的意思:
- 初识nginx——内存池篇
初识nginx——内存池篇 为了自身使用的方便,Nginx封装了很多有用的数据结构,比如ngx_str_t ,ngx_array_t, ngx_pool_t 等等,对于内存池,nginx设计的十分精炼 ...
- MySQLi面向对象实践--insert、update、delete
执行insert <?php $mysqli = new Mysqli(); $mysqli->connect("localhost","root" ...
- Docker查看容器IP
https://segmentfault.com/q/1010000001637726 https://blog.csdn.net/sannerlittle/article/details/77063 ...