当前位置:首页 > Windows程序 > 正文

WindowsAzure Powershell脚本定时启动关机Azure VM

2021-05-24 Windows程序

标签:windowsazure powershell脚本定时启动关机azure vm

WindowsAzure Powershell脚本定时启动关机Azure VM

说到windowsazure对于当下不是一个新鲜话题了,,但是对于功能来说还是有点期待的,毕竟在云服务的世界里windowsazure还是一个菜鸟了。同样我们都知道,对于windowsazure上的服务操作我们有很多方式可以操作,比如:portal页面,powershell with azure及azure pack等,其他的都是图形界面操作,操作相对简单,今天咱们就说说通过windows azure powershell命令来管理windows azure上的部分服务,powershell操作命令及脚本相信大家都不去陌生了,扩展名为.ps1的文件为powershell脚本文件。其实说到powershell。我个人对微软的powershell有很大意见:因为什么呢,不同的服务需要安装不同的powershell程序,比如:Windows系统自带的powershell程序仅仅能对操作系统及服务进行操作,Exchange powershell(ems)对exchange相关服务进行操作管理,还有就是一个windows Azure powershell,他们之间不能互相通用,如果拿windows azure的powershell来说,如果系统自带的powershell能在线导入一个windows azure的powershell模块的话那样也行,但是对于微软来说貌似还是分开的,废话不多说了,进入今天的主题。

试验最初的目的是为了节省成本,为什么这么说呢,因为微软的azure服务收费相当高,尽管是以单位或者运行时间来计算成本,但是数量多了还是一笔不小的开销。但是前提还是需要一台稳定的服务器来通过系统自带的计划任务来定义任务条件执行程序,所以我想对windows azure上的vm进行定时关机及启动。如果要使用windows azure powershell来管理windows azure服务的话,首先需要下载windows azure账户订阅文件,然后导入到windows azurepowershell运行的系统中。具体方法见下:

我们需要首先下载对应的windowsazure 订阅

https://manage.windowsauzre.cn/publishsettings

技术分享

然后下载并且安装windowsazure powershell,然后在windowsazure powershell下导入该订阅文件;访问 ---> 文档和资源---> azure 命令行接口---->windows安装就会提示下载windowsazure powershell

技术分享

我们同样可以查看上面的windows powershell的相关文档

具体方法可以浏览网页内部

下载后就是安装,根据提示安装完powershell即可

技术分享

Import-AzurePublishSettingsFile custom.publishsettings

文件以供模块使用

技术分享

因为我已经导入过了,所以再次导入会提示以下信息

技术分享

如果在windowsazure powershell中导入多个订阅文件的话,我们需要选择默认的

我们首先通过

get-azuresubscrpit

查看当前powershell下已导入的订阅文件

技术分享

我们发现有两个,所以我们需要通过以下命令来设置默认的即可

Select-azuresubscript -subsciptionName "xxxxx" -default

然后我们可以

Get-azurevm

查看当前订阅性的所有vm信息

我们可以通过该powershell去启动该虚拟机

Start-AzureVM

Starts a Windows Azure virtual machine.

Parameter Set: ByName  

Start-AzureVM [-ServiceName] <String> [-Name] <String> [ <CommonParameters>]

Parameter Set: Input  

Start-AzureVM [-ServiceName] <String> -VM <PersistentVM> [ <CommonParameters>] -Name<String>

Specifies the name of the virtual machine to start.

Aliases

 

none

 

Required?

 

true

 

Position?

 

2

 

Default Value

 

none

 

Accept Pipeline Input?

 

true

 

Accept Wildcard Characters?

 

false

 


-ServiceName<String>

Specifies the name of the Windows Azure service that contains the virtual machine to start.

Aliases

 

none

 

Required?

 

true

 

Position?

 

1

 

Default Value

 

none

 

Accept Pipeline Input?

 

true

 

Accept Wildcard Characters?

 

false

 


-VM<PersistentVM>

Specifies a virtual machine object that identifies the virtual machine to start.

Aliases

 

none

 

Required?

 

true

 

Position?

 

2

 

Default Value

 

none

 

Accept Pipeline Input?

 

true

 

Accept Wildcard Characters?

 

false

 


温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70286.html