Azure

Create Azure SQL Server And DTU Primarily based SQL Database With TDE State Enabled Utilizing PowerShell Script

This text is targeted on creating an Azure SQL Server to a newly created Useful resource Group after which making a SQL Database of Primary Version with DTU capability with its TDE (Clear Knowledge Encryption) state as Enabled utilizing PowerShell instructions

This text is split into following 5 sections.

  1. Connecting to Azure
  2. Creating a brand new Useful resource Group
  3. Creating SQL Server to the Useful resource Group created from Step 3
  4. Creating Primary Version SQL Database
  5. Checking if TDE State is already enabled, if not, setting the TDE State to Enabled

For operating the PowerShell instructions, be sure to have AzResources Module put in, if not then run the next command to put in it to your native system

PS Script: Set up-Module -Title Az.Assets

As soon as the Module is put in, now it’s time to comply with the 5 steps talked about above,

Under talked about all of the 5 steps intimately with the PowerShell scripts,

# #Step 1 - Creating an Azure Reference to username and password
# # Connection to Azure
Write - Host "Connecting to Azure"
Join - AzAccount
# # Linked to Azure
Write - Host "Linked to Azure"
# #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - #Step2 - Creating New Useful resource Group,
    if you have already got a useful resource group you should utilize the prevailing one
# #Creating new Useful resource Group at West Europe Location
$rg = New - AzResourceGroup - Title 'rg-sqlserverautomation' - Location "West Europe"
# #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # #Step 3 - Provisioning Azure SQL Server within the Useful resource Group
# # Creating the Azure SQL Server
$azSqlServer = New - AzSqlServer `
    -ServerName 'sqlshrushti123' ` - ResourceGroupName $rg.ResourceGroupName `
    -Location $rg.Location ` - SqlAdministratorCredentials(Get - Credential)
# #Print Output - Azure SQL Server Title
Write - Host "Azure SQL Server $($azSqlServer.ServerName) within the $($rg.ResourceGroupName) is Created"
Write - Host $azSqlServer.ServerName
# #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # #Step 4 - Creating Primary Version SQL Database with DTU Capability
# #Create a Primary Version DTU based mostly SQL Database in newly provisioned SQL Server
$sqlDatabase = New - AzSqlDatabase - ResourceGroupName $rg.ResourceGroupName - ServerName $azSqlServer.ServerName - DatabaseName 'ShrushtiTestDatabase' - Version 'Primary'
Write - Host "Azure SQL Server $($azSqlServer.ServerName) within the $($rg.ResourceGroupName) is Created"
Write - Host $sqlDatabase.DatabaseName
# #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # # Print the DTU Capability of the SQL Database
# #Verify the SQL Database Capability
$fetchDatabase = Get - AzSqlDatabase - ResourceGroupName $rg.ResourceGroupName - ServerName $azSqlServer.ServerName
Write - Host "For Chosen SQL Serve $($azSqlServer.ServerName) the DTU Capability is  $($fetchDatabase.Capability)"
# #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - # #Step 5 - Checking
if TDE state is Enabled
if not, then setting the TDE State as Enabled
# #Verify
if the TDE State is already Enabled
$validateTDE = Get - AzSqlDatabaseTransparentDataEncryption - ServerName $azSqlServer.ServerName - ResourceGroupName $rg.ResourceGroupName - DatabaseName $fetchDatabase.DatabaseName - State "Enabled"
if ($validateTDE.State - eq "Enabled") {
    Write - Host "TDE State for SQL Database is already Enabled"
} else {
    # # Set the Clear Knowledge Encryption as Enabled to SQL database
    $setTDEState = Set - AzSqlDatabaseTransparentDataEncryption - ResourceGroupName $rg.ResourceGroupName--ServerName $azSqlServer.ServerName - DatabaseName $fetchDatabase.DatabaseName - State "Enabled"
    Write - Host "TDE State for SQL Database is about to Enabled"
}
# #-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -

Now, let’s confirm if the script has run completely or not by checking it

Navigate to https://portal.azure.com -> Useful resource Group -> Created Useful resource Group -> You’ll discover the created SQL Server -> Within the SQL Server -> SQL Database -> Clear Knowledge Encryption -> It ought to be set as Enabled


Fig 1.1 – SQL Server Provisioned

Create Azure SQL Server and DTU based SQL Database with TDE State Enabled using PowerShell script
Fig 1.2 – SQL Database of Primary Version provisioned Within the SQL Server

Create Azure SQL Server and DTU based SQL Database with TDE State Enabled using PowerShell script
Fig 1.3 – TDE state is Enabled within the SQL Database

I hope this text appears helpful for all of the Azure fans on how they will provision SQL Server and SQL Database utilizing PowerShell scripts.

Maintain Studying!

Maintain Sharing!

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button