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.
Table of Contents
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
- CategoryInfo : ObjectNotFound: (Set-AzSqlDatabase:String) [], CommandN
You can see it here below
To solve the error “The ‘Set-AzSqlDatabase’ command was found in the module ‘Az.Sql’“, I followed the below steps
- 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)
- Run the below command to import the Az.Sql module.
Import-Module Az.Sql
You will get the Output below
After that, I executed the script again to rename the Azure SQL database, and this time, it worked for me without any issues.
Note: I have changed the server name on the above script because of another separate issue.
You may also like following the articles below
- 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 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 !!!.
I am Rajkishore, and I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machine, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.