When I remove an automation account in the Azure console it will remove the run as account connected to the automation account. When I run the 'Remove-AzAutomationAccount' command it will not remove the run as account. How can I remove the run as account through powershell when I'm removing the automation account?
You could remove the run as account via Remove-AzADApplication
, try the command as below, it works fine on my side.
$connection = Get-AzAutomationConnection -ResourceGroupName <ResourceGroupName> -AutomationAccountName <AutomationAccountName> -Name AzureRunAsConnection
$appid = $connection.FieldDefinitionValues.ApplicationId
Remove-AzADApplication -ApplicationId $appid
Remove-AzAutomationAccount -ResourceGroupName <ResourceGroupName> -Name <AutomationAccountName>