使用本地计划任务定时关闭azure虚拟机
本文包含以下内容
前提条件
Controller 机器上必须安装 Azure PowerShell,并且要在 PowerShell 里登录一次 Azure, 请参见:如何安装和配置 Azure PowserShell
如何实现定时关闭虚拟机
配好 Azure PowerShell 以后,就可以用下面这个脚本创建定时关机任务。把下面的代码另存为一个 PowerShell 脚本保存到本地磁盘,比如叫Stop-AzureVMsOnSchedule.ps1
<# .synopsis="" creates="" scheduled="" tasks="" to="" stop="" virtual="" machines.="" .description="" creates="" scheduled="" tasks="" to="" stop="" a="" single="" virtual="" machine="" or="" a="" set="" of="" virtual="" machines="" (using="" wildcard="" pattern="" syntax="" for="" the="" virtual="" machine="" name).="" .example="" stop-azurevmsonschedule.ps1="" -servicename="" "myservicename"="" -vmname="" "testmachine1"="" -taskname="" "stopt="" test="" machine="" 1"="" -at="" 5:30pm="" stop-azurevmsonschedule.ps1="" -servicename="" "myservicename"="" -vmname="" "test*"="" -taskname="" "stop="" all="" test="" machines"="" -at="" 5:30pm="" #="">
param(
# The name of the VM(s) to start on schedule. Can be wildcard pattern.
[Parameter(Mandatory = $true)]
[string]$VMName,
# The service name that $VMName belongs to.
[Parameter(Mandatory = $true)]
[string]$ServiceName,
# The name of the scheduled task.
[Parameter(Mandatory = $true)]
[string]$TaskName,
# The name of the "Stop" scheduled tasks.
[Parameter(Mandatory = $true)]
[DateTime]$At
)
# The script has been tested on Powershell 3.0
Set-StrictMode -Version 3
# Following modifies the Write-Verbose behavior to turn the messages on globally for this session
$VerbosePreference = "Continue"
# Check if Azure Powershell is avaiable
if ((Get-Module -ListAvailable Azure) -eq $null)
{
throw "Azure Powershell not found! Please install from http://www.windowsazure.com/en-us/downloads/#cmd-line-tools"
}
# Define a scheduled task to stop the VM(s) on a schedule.
$stopAzureVM = "Stop-AzureVM -Name " + $VMName + " -ServiceName " + $ServiceName + " -Force -Verbose"
$stopTaskTrigger = New-ScheduledTaskTrigger -Daily -At $At
$stopTaskAction = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument $stopAzureVM
$startTaskSettingsSet = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries
$stopScheduledTask = New-ScheduledTask -Action $stopTaskAction -Trigger $stopTaskTrigger -Settings $startTaskSettingsSet
# Register the scheduled tasks to start and stop the VM(s).
Register-ScheduledTask -TaskName $TaskName -InputObject $stopScheduledTask
还是刚才那个文件,右键用 PowerShell 运行,按 PowerShell 提示输入四个必要的参数:
- VMName, 要关闭的 Virtual Machine 名称
- ServiceName, 关联的服务名称
- TaskName, 任务名称
- At,具体操作时间
然后到计划任务列表里就能刷出这个定时关机的任务了,可以测一下:
到指定时间 powershell 开始执行关闭虚拟机的操作。
到 Portal 里验证一下,已经成功关机了.
立即访问http://market.azure.cn
使用本地计划任务定时关闭azure虚拟机的更多相关文章
- 关闭Azure虚拟机
Press the Windows key, and then in the Start page, located at the bottom-left, click the Power butto ...
- 使用Azure Automation(自动化)定时关闭和启动虚拟机
1. 概述 作为Windows Azure的用户,使用Azure的过程中,最担心的事情就是还没到月底,预设的费用就快消耗完了(下面两张账单图是我最讨厌看到的).但是仔细分析自己的费用列表,发现绝大部分 ...
- Azure Site Recovery 通过一键式流程将虚拟机故障转移至 Azure虚拟机
Ruturaj Dhekane 云 + Enterprise 项目经理 现在,AzureSite Recovery可以通过其"灾难恢复至 Azure"功能保护您的工作负荷,并 ...
- 在 Windows Azure 虚拟机中使用 Microsoft SQL Server 安全功能
编辑人员注释:本文章由 SQL Server 团队高级项目经理 Sung Hsueh 撰写. SQL Server 的最新用法之一是利用 Microsoft 的 Windows Azure 基础结构服 ...
- Kubernetes 1.12公布:Kubelet TLS Bootstrap与Azure虚拟机规模集(VMSS)迎来通用版本号
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/M2l0ZgSsVc7r69eFdTj/article/details/82880341 https: ...
- windows 定时任务:schtasks,定时关闭网易云音乐
大部分属于转载和粘贴. 使用命令:schtasks windows 定时任务 使用样例: 每天定时关闭网易云音乐: 每天22:20关闭网易云音乐: schtasks /create /tn &qu ...
- 在 Azure 虚拟机中配置 Always On 可用性组(经典)
在开始之前,请先假设现在可以在 Azure Resource Manager 模型中完成此任务. 我们建议使用 Azure Resource Manager 模型来进行新的部署. 请参阅 Azure ...
- 利用Azure虚拟机安装Dynamics 365 Customer Engagement之六:安装后端服务器
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
- 利用Azure虚拟机安装Dynamics 365 Customer Engagement之七:安装前端服务器及部署管理器
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...
随机推荐
- mysql 查询月份数据.
//查看本月数据 SELECT *FROMcontent_publishWHEREdate_format(publish_time, '%Y %m') = date_format(DATE_SUB(c ...
- 洛谷 P2482 loj #2885 [SDOI2010]猪国杀 题解【模拟】【贪心】【搜索】
好玩的模拟题. 以后要经常写模拟题鸭 题目描述 游戏背景 <猪国杀>是一种多猪牌类回合制游戏,一共有\(3\)种角色:主猪,忠猪,反猪.每局游戏主猪有且只有\(1\)只,忠猪和反猪可以有多 ...
- DFS/BFS视频讲解
视频链接:https://www.bilibili.com/video/av12019553?share_medium=android&share_source=qq&bbid=XZ7 ...
- PHP CURL_ERRNO 77
项目中碰到curl https偶尔出现false,错误码77,可以尝试下面两种解决方法: 1.确认安装机器ca-certificates,重启PHP.设置curl_setopt($ch, CURLOP ...
- jquery 去除字符串左右空格
/*** 删除左右两端的空格*/String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g, '');} 调用方式: v ...
- innoback 参数及使用说明
--defaults-file 同xtrabackup的--defaults-file参数,指定mysql配置文件; --apply-log 对xtrabackup的--prepare参数的封装; - ...
- mysql DML语句
1, 插入数据 insert into emp1(ename,hiredate,sal,deptono) values('kingle','2000-01-01','2000',1); 插入数据加入需 ...
- 原生态hadoop2.6平台搭建
hadoop2.6平台搭建 一.条件准备 软件条件: Ubuntu14.04 64位操作系统,jdk1.7 64位,Hadoop 2.6.0 硬件条件: 1台主节点机器,配置:cpu 8个,内存32 ...
- vi编辑器备忘录
1. 基本操作 G 移动到文件最后一行 nG 移动到n行 gg 移动到第一行 N[Enter] 向下移动n行 /word 向下寻找 ?word 向上寻找 n 查找下一个 N 查找上一个 0或者Home ...
- Oracle使用sys登录时报错ORA-28009解决方法
情况一:使用sqlplus登录: 正常输入用户名的口令,就会报错,因为SYS是在数据库之外的超级管理员,所以我们在登录的时候 要在输入口令:口令+as sysdba(比如:123456 as sysd ...