7.0.6 LTS
, PowerShell 7.1.3
, or higher
is recommended by Microsoft.$PSVersionTable.PSVersion
We can use the below terminal to run the PowerShell commands.
Note: It takes a minute to start and install necessary things when we connect to the terminal for the first time. We’ll have to wait till it initializes PowerShell.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
We can check the execution policy with the following command.
Get-ExecutionPolicy -List
Az
module.Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
It will provide a link that can be opened in the browser, where we enter the code that has been provided.
Connect-AzAccount -UseDeviceAuthentication
After successfully logging in, it will print our Account
, SubscriptionName
, TenantId
, and Environment
.
We’ve set up everything that’s needed to create an Azure SQL Server using PowerShell.
New-AzSqlServer -ResourceGroupName "demoRG" -Location "Central US" -ServerName "demosvr" -ServerVersion "12.0" -SqlAdministratorCredentials (Get-Credential)
In the above command, we see the following:
New-AzSqlServer
creates an Azure SQL server.demoRG
is the resource group name where our SQL server resource will reside. demoRG
must be created before executing this command.Central US
.demosvr
.(Get-Credential
asks for credentials.It will take some time to create a SQL server and print the details when it is created.