![](/img/trans.png)
[英]Can we do script to auto restart for Services if the VM Agent status is not ready using Powershell?
[英]Using powershell can we do automation script to auto restart the azure vm agent if the agent is not responding?
1)驗證 Azure VM 代理狀態 2)如果狀態良好,不需要重新啟動代理。 如果狀態解除,需要重新啟動代理。
試試下面的命令,它會在虛擬機被釋放時重新啟動它。
$vm = Get-AzVM -ResourceGroupName <resource-group-name> -Name <VM-name> -Status
if($vm.Statuses[1].Code -eq 'PowerState/deallocated'){
$vm | Start-AzVM
}else{
Write-Output "The VM was not deallocated."
}
如果您還想以PowerState/starting, PowerState/deallocating
的狀態重新啟動 VM,可以使用如下命令。
$vm = Get-AzVM -ResourceGroupName <resource-group-name> -Name <VM-name> -Status
if($vm.Statuses[1].Code -ne 'PowerState/running'){
$vm | Start-AzVM
}else{
Write-Output "The VM is running."
}
您應該首先檢測是否安裝了 VM 代理:
Get-AzVM
結果:
OSProfile :
ComputerName : myVM
AdminUsername : myUserName
WindowsConfiguration :
ProvisionVMAgent : True
EnableAutomaticUpdates : True
Azure VM 代理可能已停止、過時、在不一致的 state 中或未安裝並阻止 Azure 備份服務觸發快照。
如果 VM 代理已停止或處於不一致的 state 中,請重新啟動代理並重試備份操作(嘗試臨時備份)。 有關重新啟動代理的步驟,請參閱Windows VM或Linux VM 。
如果 VM 代理未安裝或已過時,請安裝/更新 VM 代理並重試備份操作。 有關安裝/更新代理的步驟,請參閱Windows VM或Linux VM 。
為了在 Linux 上運行進程,請執行以下操作:
https://docs.microsoft.com/en-us/azure/virtual-machines/linux/run-command
Windows:
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/run-command
參考: https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/agent-windows#detect-the-vm-agent
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.