In this article, we will discuss how to fix the error “The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql’, but the module could not be loaded.” which i got while executing a PowerShell script to rename the Azure SQL database.
Table of Contents
The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql’
Recently, I had a requirement to rename the Azure SQL database using PowerShell. I tried executing the below script and all of sudden I got the above error.
Set-AzSqlDatabase -DatabaseName 'TsInfoSQLOld' -NewName 'TsInfoSQLNewDB' -ServerName 'tsinfo.database.windows.net' -ResourceGroupName 'DEMORG1'
After executing the above script, I got the below error. This is the complete error message that I got.
Set-AzSqlDatabase : The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql’,
but the module could not be loaded. For more information, run ‘Import-Module Az.Sql’.
At line:1 char:1
- Set-AzSqlDatabase -DatabaseName ‘TsInfoSQLOld’ -NewName ‘TsInfoSQLNew …
~~~~~- CategoryInfo : ObjectNotFound: (Set-AzSqlDatabase:String) [], CommandN
otFoundException - FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
- CategoryInfo : ObjectNotFound: (Set-AzSqlDatabase:String) [], CommandN
You can see it here as below

If you are getting the same issue, I have a quick solution for you.
The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql’ [Solved]
- Open a new PowerShell secssion. (You can continue with the same PowerShell session or if you are getting any error use a new PowerShell window)
- Run the below command to import the Az.Sql module.
Import-Module Az.Sql
You will get the Output like below

After that I have executed the script again to rename the Azure SQL database and this time it worked for me without any issue.

Note: On the above script I have changed the server name because of another separate issue.
You may also like following the below articles
- The ‘New-AzSqlServer’ command was found in the module ‘Az.Sql’, but the module could not be loaded
- How to create an Azure SQL database
- How To Change User Id And Password For Azure SQL Server Database
- Cannot Open Server Requested By The Login Azure SQL
- How To Revert SQL Azure Database
- How to Export Azure SQL Database
Wrapping Up
In this artilce we discussed how easy to solve the error “The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql’” using the above provided information. Thanks for reading this article !!!.