本文简单提供了一个Azure powershell脚本,能实现如下功能

  1. Azure (China)账户是否已经登陆了,如果没登陆,会提示你登陆。
  2. 要创建的资源组是否存在,存在的话不再创建,直接部署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 &quot;deploy begin&quot;
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName <code>
-TemplateFile $deployPath </code>
-TemplateParameterFile $deployParameterPath
}
## 检测资源组是否存在,逻辑行为可定制。
## reousrceGroup的部署是增量的形式,组下的已有资源不再被重新部署。
$resourceGroup = Get-AzureRmResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue
if ( -not $ResourceGroup ) { Write-Output &quot;Could not find resource group '$ResourceGroupName' - will create it&quot; Write-Output &quot;Creating resource group '$ResourceGroupName' in location '$Location'&quot;
New-AzureRmResourceGroup -Name $resourceGroupName -Location $Location
Deployment .\Desktop\template\template\azuredeploy.json .\Desktop\template\template\azuredeploy.parameters.json
}
else {
Write-Output &quot;Using existing resource group '$ResourceGroupName'&quot;
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的更多相关文章

  1. Azure Powershell使用已有Image创建ARM非托管磁盘虚拟机

    生成Image映像文件,记录好Image的URL(下面URL为测试URL,具体请参考实际):ImageURL:https://hlmrgstoragen.blob.core.chinacloudapi ...

  2. 【Azure 微服务】Service Fabric, 使用ARM Template方式来更新SF集群的证书(Renew SF Certificate)

    问题描述 因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)一文中,描述了因为证书过期而导致了SF集群不可用,并且通过命令dd-AzServiceFabricCluster ...

  3. Azure Powershell对ARM资源的基本操作

    本分主要介绍Windows Azure Powershell对ARM资源的基本操作 1.登陆ARM模式,命令:Login-AzureRmAccount -EnvironmentName AzureCh ...

  4. Azure PowerShell (13) 批量设置Azure ARM Network Security Group (NSG)

    <Windows Azure Platform 系列文章目录> 刚刚在帮助一个合作伙伴研究需求,他们的虚拟机全面的网络安全组(Network Security Group, NSG)会经常 ...

  5. 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 ...

  6. Azure PowerShell (14) 批量导出Azure ASM ACL和ARM NSG配置信息

    <Windows Azure Platform 系列文章目录> 最近有一个客户需求,需要批量导出Azure Classic VM的ACL (Access Control List), 还有 ...

  7. 通过Azure Powershell获取asm及arm虚拟机的配置信息

    1.asm虚拟机可以使用类似如下Azure Powershell命令获取虚拟机的基本信息,包括发行版本,虚拟机名称及size[备注:虚拟机需要是使用平台image创建的] PS C:\Users\he ...

  8. Windows 上安装 Azure PowerShell及Azure PowerShell部署虚拟机

    一.Azure PowerShell部署   1.使用 PowerShellGet 在 Windows 上安装 Azure PowerShell 从 Azure PowerShell 版本 6.0 开 ...

  9. Azure Powershell部署使用平台映像的托管Windows VM及相关问题说明

    1.脚本背景信息: a.使用平台镜像(Windows Server 2016 zh-cn)部署高性能托管磁盘虚拟机 b.虚拟机默认不开启Boot诊断 c.添加三块已经创建好的数据磁盘 d.添加已创建好 ...

随机推荐

  1. pyenv+virtual 笔记

    Pyenv + virtualEnv 设置 安装这两个组件是为了适应不同版本的python在同一个系统下的运行:例如现在最明显就是python2.7和python3.6的两个版本,很多库依旧是使用了P ...

  2. GNU构建系统和AutoTools

    注:本篇博客是阅读文末[参考博客]的讲解所写,内容非原创,仅是学习笔记 1. 概述2. 不同视角的程序构建2.1 用户视角2.2 开发者视角3. 导图图片4. configure选项参考博客 1. 概 ...

  3. vue侧边栏导航和右边内容一样高

    vue侧边栏导航和右边内容一样高吗? 失败了,最后用做导航和上导航 定位, 右内容类似滚动条 效果: 直接把top导航和左侧导航栏display:flxed定位左边,右边内容left: top

  4. ASP.NET Forms验证

    /// <summary> /// 执行用户登录操作 /// </summary> /// <param name="config">授权配置信 ...

  5. slot 插槽的作用域用法(摘自vue.js 官网)

    有的时候你希望提供的组件带有一个可从子组件获取数据的可复用的插槽.例如一个简单的 <todo-list> 组件的模板可能包含了如下代码: <ul> <li v-for=& ...

  6. Vert.x简介

    https://vertx.io/ https://vertx.io/download/ https://baike.baidu.com/item/Vert.x 近年来,移动网络.社交网络和电商的兴起 ...

  7. linux_目录基本操作

    ls命令 ls命令用来显示目标列表,在Linux中是使用率较高的命令.ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件. 语法 $ ls [选项] [目录] 选项 说明 -a 显示所有档案 ...

  8. 智能制造(MES)四大阶段

    智能制造的发展会经历标准化.自动化.信息化.智能化四个阶段标准化,对于生产流程.业务流程.生产制造多方面的标准化.质量检测标准化.企业管理.供应链等.标准化是组织现代化生产的重要组成部分,对于生产专业 ...

  9. 记一次配置oh my zsh的坑

    oh-my-zsh:https://github.com/robbyrussell/oh-my-zsh prezto:https://github.com/sorin-ionescu/prezto 我 ...

  10. 自省 另外一种python 生成随机在base36 之间的兑换码生成。

    放假无聊,翻看自己博客的时候发现自己前面写的 那个base36兑换码在翻阅的时候 想到一个更简单的办法实现.但是随机上来说可能没有前者那么高 但是觉得也没有多大的问题 发上来 自己再想想 import ...