I currently have runbooks that stop/start VMs on a schedule but recently the runbook to start vms is stopped because it takes too long to complete. The following message is thrown -
"The job has been stopped because it reached the fair share limit of job execution more than 3 hours. For long-running jobs, it's recommended to use a Hybrid Runbook Worker. Hybrid Runbook Workers don't have a limitation on how long a runbook can execute."
I've never used a hybrid runbook before so here's my question - can a hybrid runbook be used to stop/start multiple Azure VM's? I haven't been able to find anything on this, it looks like the hybrid approach is used to pull info or perform operations inside the VM.
I'm ultimately looking to manage VM resources (stop/start VMs) from within an Azure VM if possible. See current runbook below:
Write-Output "------------------------ Authentication ------------------------"
Write-Output "Logging in to Azure ..."
$ConnectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$Conn = Get-AutomationConnection -Name $ConnectionName
# Logging into Azure
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
Write-Output "Successfully logged in to Azure."
}
catch
{
if (!$Conn)
{
$ErrorMessage = "Connection $ConnectionName not found."
throw $ErrorMessage
}
else
{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
Write-Output "------------------------ Starting Virtual Machines ------------------------"
## Sequence VMs are started
$Computers = @(
'virtualmachines(x11)'
)
foreach($c in $Computers)
{
$AzResource = Get-AzResource -Name $c -ResourceType "Microsoft.Compute/virtualMachines"
if($null -ne $AzResource)
{
Write-Output "Starting virtual machine..." + $c
Start-AzVM -ResourceGroupName $AzResource.ResourceGroupName -Name $c
# Pauses 4 minutes before continuing loop
Start-Sleep -Seconds 240
}
else
{
throw "Virtual machine not found:" + $c
}
}
Thanks,