we have a problem with a Microsoft bot hosted in Azure. As long as we haven't resolved it, we want to periodically restart it.
We found 3 sets of powershell commands and spent the full day on it without making it work.
Solution 1:
- we found the cmdlets : Get-AzCloudService Restart-AzCloudService.
- We didn't understand from the documentation what module to install.
- It returns : The term 'Restart-AzCloudService' is not recognized as the name of a cmdlet.
- They talk about an obscure "extended support" to have access to it.
Solution 2:
We are able to list the cloud service using:
- Connect-AzAccount
- get-azresource -name $serviceName -resourcetype "Microsoft.BotService/botServices"
But we do not find the cmdlet to restart the resource.
Solution 3:
- Reset-AzureRoleInstance -serviceName $serviceName -Slot "production" -InstanceName $serviceName
- Error : No default subscription has been designated. Use Select-AzureSubscription -Default
- We are using MFA. Login-AzureRmAccount systematically fails , evenly saying that our account is disabled.
We did no manager to run the sequence:
- Login-AzureRmAccount
- Select-AzureSubscription -Default
- Reset-AzureRoleInstance -serviceName $serviceName -Slot "production" -InstanceName $serviceName
The idea is to run this script twice a day, either from a VM or from an Azure Runbook. We managed to run this code using an automation Account but we are still missing the last command that would restart the bot (that we consider a cloud service).
Param()
$automationAccount = "xxx"
$resourceGroup = "xxx"
$serviceName = "xxx"
$subscriptionname ="xxx"
$subscriptionid ="xxx"
# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process | Out-Null
# Connect using a Managed Service Identity
try {
$AzureContext = (Connect-AzAccount -Identity).context
}
catch{
Write-Output "There is no system-assigned user identity. Aborting.";
exit
}
#Set-AzureSubscription -SubscriptionId $subscriptionid
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription `
-DefaultProfile $AzureContext
get-azresource -name $serviceName -resourcetype "Microsoft.BotService/botServices"