简体   繁体   English

有没有办法在 azure 中创建一个 PowerShell 脚本在虚拟机空闲时间自动停止虚拟机?

[英]Is there a way to create a PowerShell script to stop the virtual machine automatically during the idle time of the virtual machine in azure?

Please suggest me the powershell script to stop a virtual machine IN AZURE when it attains given maximum idle time and after that it must automatically starts running when the user logs into that virtual machine?请建议我使用 powershell 脚本在虚拟机 IN AZURE 达到给定的最大空闲时间时停止它,之后它必须在用户登录到该虚拟机时自动开始运行?

One way to accomplish this is to create a scheduled task inside the VM.实现此目的的一种方法是在 VM 内创建计划任务。 That scheduled task will trigger when the machine is idle.该计划任务将在机器空闲时触发。 The script the task will run is:任务将运行的脚本是:

Stop-AzVM -Name <VM name> -ResourceGroupName <RG Name> -Force

As for the second part of starting when a user logs on, that is not possible.至于用户登录时启动的第二部分,这是不可能的。 The VM will be off/de-allocated, there is nothing to log on to.虚拟机将被关闭/取消分配,没有什么可以登录的。

NOTE: the VM that has the scheduled task will also need the Azure Powershell modules installed on it and a system managed identity .注意:具有计划任务的 VM 还需要安装 Azure Powershell 模块和系统管理标识

创建任务图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM