Set-AzSqlDatabase

In this article, we will discuss the syntax and usage of the Set-AzSqlDatabase PowerShell command. Then we will also 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 the Set-AzSqlDatabase PowerShell command to rename the Azure SQL database.

Set-AzSqlDatabase

Recently, I had a requirement to rename the Azure SQL database using PowerShell. I tried executing the below script using the Set-AzSqlDatabase PowerShell command.

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 below

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

To solve the error “The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql’“, I followed the below steps

  1. Open a new PowerShell session. (You can continue with the same PowerShell session, or if you are getting any errors 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 below

Import Module Az Sql

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

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

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

You may also like following the articles below

Wrapping Up

In this article, we discussed the syntax and usage of the Set-AzSqlDatabase PowerShell command. Then we discussed fixing the error “The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql'” using the above-provided information. Thanks for reading this article !!!.