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.添加已创建好 ...
随机推荐
- Ionic 2 中生命周期的命名改变及说明
原文发表于我的技术博客 本文简要整理了在 Ionic 2 的版本中生命周期命名的改变,以及各个事件的解释. 原文发表于我的技术博客 在之前的课程中讲解了 Ionic 生命周期的命名以及使用,不过在 I ...
- 转:SpringMVC之类型转换Converter(GenericConverter)
转: http://blog.csdn.net/fsp88927/article/details/37692215 SpringMVC 之类型转换 Converter 1.1 目录 1.1 目录 1. ...
- Redis+Keepalived高可用环境部署记录
Keepalived 实现VRRP(虚拟路由冗余)协议,从路由级别实现VIP切换,可以完全避免类似heartbeat脑裂问题,可以很好的实现主从.主备.互备方案,尤其是无状态业务,有状态业务就需要额外 ...
- rrd文件及rrd文件与实际数据的对比研究。
一,什么是rrd文件? 所 谓的“Round Robin” 其实是一种存储数据的方式,使用固定大小的空间来存储数据,并有一个指针指向最新的数据的位置.我们可以把用于存储数据的数据库的空间看成一个圆,上 ...
- C_数据结构_递归实现求阶乘
# include <stdio.h> int main(void) { int val; printf("请输入一个数字:"); printf("val = ...
- A. Make a triangle!
题意 给你三条边a,b,c问使得构成三角形,需要增加的最少长度是多少 思路 数学了啦 代码 #include<bits/stdc++.h> using namespace std; #de ...
- 2-Twenty First Scrum Meeting-20151221
任务安排 成员 今日完成 明日任务 闫昊 请假(数据库) 唐彬 请假(数据库) 史烨轩 尝试使用downloadmanager对notification进行更新 尝试使用downloadm ...
- git学习心得
https://github.com/zhangxinn/test/tree/master 自己虽然在课堂上有认真的听老师讲解如何使用github,包括怎样在线学习,怎样在github上建立自己的仓库 ...
- FMDB数据库升级
FMDBMigrationManager 是与FMDB结合使用的一个第三方,可以记录数据库版本号并对数据库进行数据库升级等操作.首先要集成FMDB和FMDBMigrationManager,建议使用c ...
- msyql sql语句收集
在不断的学习中,发现了一些新的slq语句,总结于此. 一.复制数据表的sql 1)create table tableName as select * from tableName2 ...