The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql’

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.

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

You can see it here as below

The 'Set-AzSqlDatabase' command was found in the module 'Az.Sql'

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]

  1. 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)
  2. Run the below command to import the Az.Sql module.
Import-Module Az.Sql

You will get the Output like below

Import Module Az Sql

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

The 'Set-AzSqlDatabase' command was found in the module 'Az.Sql' error

Note: On the above script I have changed the server name because of another separate issue.

You may also like following the below articles

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 !!!.