1
votes

How to reset the sql admin password on Azure SQL Managed Instance if there is only one user/admin and the admin password is lost/forgotten?

Could it be done via portal or using some script?

1

1 Answers

3
votes

The easiest way to reset the password is to go to the Azure portal, open the instance details blade and press Reset password button:

Reset sql admin password using the Azure portal

As an alternative, you can use AzureRm.Sql PowerShell library and Set-AzureRmSqlManagedInstance command:

$InstancePassword = "Newpassword1234"
$SecureString = ConvertTo-SecureString $InstancePassword -AsPlainText -Force
Set-AzureRmSqlInstance -Name "managedinstance1" -ResourceGroupName "ResourceGroup01" -AdministratorPassword $SecureString 

You can also use Azure CLI with az sql mi update command:

az sql mi update -g mygroup -n myinstance -i -p mypassword