Migrate to Innovate Summit:
Learn how migrating and modernizing to Azure can boost your business's performance, resilience, and security, enabling you to fully embrace AI.Register now
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This quickstart steps through creating a Windows SQL Server on Azure Virtual Machine (VM) with Azure PowerShell.
Tip
This quickstart provides a path to quickly provision and connect to a SQL Server VM. For more information about other Azure PowerShell options to create SQL Server VMs, see the Provisioning guide for SQL Server VMs with Azure PowerShell.
To complete this quickstart, you should have the following:
An Azure subscription. If you don't have an Azure subscription, create a free account before you begin.
The latest version of Azure PowerShell
Note
This article uses the Azure Az PowerShell module, which is the recommended PowerShell module for interacting with Azure. To get started with the Az PowerShell module, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Connect to Azure
Open PowerShell and establish access to your Azure account by running the Connect-AzAccount command, and set your subscription context with Set-AzContext.
When you see the sign-in window, enter your credentials. Use the same email and password that you use to sign in to the Azure portal.
Create a resource group
Define variables for a unique resource group name and provide a location of a target Azure region for all VM resources. Then use New-AzResourceGroup to create your resource group. To simplify the rest of the quickstart, the remaining commands use this name as a basis for other resource names.
PowerShell
$ResourceGroupName = "sqlvm1"$Location = "East US"$ResourceGroupParams = @{
Name = $ResourceGroupName
Location = $Location
Tag = @{Owner="SQLDocs-Samples"}
}
New-AzResourceGroup @ResourceGroupParams
Create a virtual machine configuration object with New-AzVMConfig and then create the VM with New-AzVM. The following command creates a SQL Server 2022 Developer Edition VM on Windows Server 2022.
# Register the SQL IaaS Agent extension to your subscriptionRegister-AzResourceProvider -ProviderNamespace Microsoft.SqlVirtualMachine
Next, register your SQL Server VM with the SQL IaaS Agent extension by using New-AzSqlVM:
PowerShell
$License = 'PAYG'# Register SQL Server VM with the extensionNew-AzSqlVM -Name$VMName -ResourceGroupName$ResourceGroupName -Location$Location `
-LicenseType $License
Pass the returned IP address as a command-line parameter to mstsc to start a Remote Desktop session into the new VM.
mstsc /v:<publicIpAddress>
When prompted for credentials, choose to enter credentials for a different account. Enter the username with a preceding backslash (for example, \azureadmin), and the password that you set previously in this quickstart.
Connect to SQL Server
After signing in to the Remote Desktop session, launch SQL Server Management Studio 2017 from the start menu.
In the Connect to Server dialog box, keep the defaults. The server name is the name of the VM. Authentication is set to Windows Authentication. Select Connect.
You're now connected to SQL Server locally. If you want to connect remotely, you must configure connectivity from the Azure portal or manually.
Clean up resources
If you don't need the VM to run continuously, you can avoid unnecessary charges by stopping it when not in use. The following command stops the VM but leaves it available for future use.
You can also permanently delete all resources associated with the virtual machine with the Remove-AzResourceGroup command. Doing so permanently deletes the virtual machine as well, so use this command with care.
Next steps
In this quickstart, you created a SQL Server 2022 virtual machine using Azure PowerShell. To learn more about how to migrate your data to the new SQL Server, see the following article.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.