Updated script and added readme

This commit is contained in:
Alexander (Sasha) Nosov
2024-08-07 18:17:18 -07:00
committed by GitHub
parent 814fbdee20
commit 1c452eed19
2 changed files with 107 additions and 43 deletions
@@ -0,0 +1,67 @@
# Overview
This script installs a pay-as-you-go SQL Server instance on your machine and automatically connext it to Azure Arc using a downloaded SQL Server media.
# Prerequisites
- You have met the [onboarding prerequisites](https://learn.microsoft.com/sql/sql-server/azure-arc/prerequisites).
- You have downloded a SQL Server image file from the workspace provided by Microsoft technical support. Tpo obtain it, open a support request using "Get SQL Installation Media" subcategory and soecify the desired version and edition.
- You are a local admin on the machine where you run the script.
- Your n
- If you are using a machine running Windows Server 2016, you have completed the mitigation steps as described below.
# Mitigating the TLS version issue on Windows Server 2016
When running the script on Windows Server 2016, the OS may be configured with a TLS version that does not meet the Azure security requirements. You need to enable strong TLS versions (TLS 1.2 and 1.3) when they are available, while still supporting older TLS versions (1.0 and 1.1) when TLS 1.2 and 1.3 are unavailable. You need to also disable versions SSL2 and SSL3, which are insecure.
To see if you need to make the change, run the command below from an elevated PowerShell prompt.
```PowerShell
[Net.ServicePointManager]::SecurityProtocol
```
If the result is `SSL3, Tls`, you need to fix the TLS version using one of the following options.
__Option 1__: run the following command below from an elevated PowerShell prompt:
```PowerShell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Tls13
```
__Option 2__: run these two commands from an elevated PowerShell prompt:
```PowerShell
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
```
After running either of these command options, close and reopen PowerShell or reboot the machine (in case currently-running applications were referencing previous values). To verify that the changes were applied correctly, run this command again:
```PowerShell
[Net.ServicePointManager]::SecurityProtocol
```
The result should be `Tls, Tls11, Tls12, Tls13`
# Launching the script
The script must be launched from and elevated PowerShell prompt. It accepts the following command line parameters:
| **Parameter**                                         | **Value**                                                                       | **Description** |
|:--|:--|:--|
|-AzureSubscriptionId|subscription_id|Required: Subscription id that will contain the Arc-enabled machime and Arc-enable SQL Server resources. That subscription will be billed for SQL Server software using a pay-as-you-go method. |
|-AzureResourceGroup |resource_group_name|Required: Resource group that will contain the Arc-enabled machime and Arc-enable SQL Server resource.|
|-AzureRegion |region name| Required: the region to store the machuine and SQL Server meta-data. |
|-SqlServerInstanceName | name of the instance|Optional: the machine name will be used if not specified|
|-SqlServerAdminAccounts | SQL Server admin accounts | Optional. By default "BUILTIN\ADMINISTRATORS" will be used.|
|-SqlServerSvcAccount| SQL Server services account |Optional. By default "NT AUTHORITY\SYSTEM" will be used.|
|-SqlServerSvcPassword| SQL Server service account password| Required if a custom service account is specified.|
|-AgtServerSvcAccount|SQL Agent service account|Optional. By default "NT AUTHORITY\NETWORK SERVICE" will be used.|
|-AgtServerSvcPassword|SQL Agent service account pasdsword|Required if a custom service account is specified.|
|-IsoFolder|Folder path|Required. The folder contrainng the files downloaded from the workspace.|
|-Proxy|HTTP proxy URL|Optional. Needed if your networks is using a HTTP proxy.|
## Example
The following command installs a SQL Server instance from the folder `c:\downloads`, connect it to subscription ID `<sub_id>`, resource group `<resource_group>` in West US, and configure it with LicenseType=PAYG. It use the default admin and service accounts and direct connectivity to Azure.
```PowerShell
.\install-payg-sql-server.ps1 -AzureSubscriptionId <sub_id> -AzureResourceGroup <resource_group> -AzureRegion westus -IsoFolder c:\downloads
```
@@ -15,6 +15,8 @@ param (
[string]$SqlServerSvcPassword,
[Parameter (Mandatory=$false)]
[string]$AgtServerSvcAccount = "NT AUTHORITY\NETWORK SERVICE",
[Parameter (Mandatory=$false)]
[string]$AgtServerSvcPassword,
[Parameter (Mandatory=$true)]
[string]$IsoFolder,
[Parameter (Mandatory=$false)]
@@ -76,9 +78,8 @@ function LoadModule
}
try {
write-host "==== Ensure PS version and load missing Azure modules ===="
#
# Suppress warnings
#
@@ -103,6 +104,7 @@ try {
write-host "==== Log in to Azure ===="
Update-AzConfig -EnableLoginByWam $false
Connect-AzAccount | Out-Null
$subscription = Get-AzSubscription -SubscriptionId $AzureSubscriptionId -ErrorAction SilentlyContinue
if (-not $subscription) {
@@ -127,31 +129,34 @@ try {
# Retrieve the product key if any
$keyFiles = Get-ChildItem $IsoFolder -Filter "*.txt"
$keyFiles = (Get-ChildItem $IsoFolder -Filter "*.txt")
$productKey = ""
foreach ($keyFile in $keyFiles) {
# Read each line from the file
Get-Content $keyFile | ForEach-Object {
if ($_ -match "(?i)$($SqlServerEdition)" -and $_ -match "[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}.*") {
Get-Content $keyFile.fullname | ForEach-Object {
if ($_ -match "[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{4,}.*") {
# Extract the product key (including any following string after a space)
$productKey = [regex]::Match($_, '[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}.*').Value
$productKey = [regex]::Match($_, '[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{5,}-[A-Z0-9]{4,}.*').Value
# Strip any text after the product key
$productKey = $productKey -replace " .*$"
}
}
}
$isoFiles = Get-ChildItem $IsoFolder -Filter "*.iso"
$isoFiles = (Get-ChildItem $IsoFolder -Filter "*.iso")
# Pick the .iso file and mount
$noKeylist = "SQLFULL_ENU_ENTVL.iso", "SQLFULL_ENU_STDVL.iso", "SQLServer2022-x64-ENU-Ent.iso", "SQLServer2022-x64-ENU-Std.iso"
foreach ($isoFile in $isoFiles) {
write-host("****isoFile: $($isoFile)")
$imagePath = $isoFile.FullName
if ($noKeylist -contains $isoFile.Name) {$productKey = ""}
if (!(Get-DiskImage -ImagePath $imagePath).Attached) {
$mountResult = Mount-DiskImage -ImagePath $imagePath
$mountResult = Mount-DiskImage -ImagePath $imagePath -PassThru
} else {
$mountResult = Get-DiskImage -ImagePath $imagePath
}
@@ -164,40 +169,31 @@ try {
write-host "==== Run unattended SQL Server setup from the mounted volume ===="
# Launch setup
$setupPath = ($driveLetter + ":\setup.exe")
$argumentList = "
/q
/ACTION=`"Install`"
/FEATURES=SQL
/INSTANCEDIR=C:\SQL
/SQLSYSADMINACCOUNTS=`"$($SqlServerAdminAccounts)`"
/SQLSVCACCOUNT=`"$($SqlServerSvcAccount)`"
/AGTSVCACCOUNT=`"$($AgtServerSvcAccount)`"
/IACCEPTSQLSERVERLICENSETERMS
"
if ($SqlServerSvcPassword) {
$argumentList += " /SQLSVCPASSWORD=`"$($SqlServerSvcPassword)`"
"
}
if ($AgtServerSvcPassword) {
$argumentList += " /SQLAGTPASSWORD=`"$($AgtServerSvcPassword)`"
"
}
if ($SqlServerInstanceName) {
$argumentList += " /INSTANCENAME=`"$($SqlServerInstanceName) `"
"
}
if ($productKey) {
$argumentList += " /PID=`"$($productKey)`"
"
}
Start-Process -FilePath $setupPath -ArgumentList $argumentList
$argumentList = "/q /ACTION=Install /FEATURES=SQL /SQLSVCACCOUNT=`"$($SqlServerSvcAccount)`" /SQLSYSADMINACCOUNTS=`"$($SqlServerAdminAccounts)`" /AGTSVCACCOUNT=`"$($AgtServerSvcAccount)`" /IACCEPTSQLSERVERLICENSETERMS"
# some optional arguments
if ($SqlServerInstanceName) {
$argumentList += " /INSTANCENAME= $($SqlServerInstanceName)"
}
if ($productKey) {
$argumentList += " /PID=`"$($productKey)`""
}
write-host "==== Dismount the ISO file after installation ===="
if ($SqlServerSvcPassword) {
$argumentList += " /SQLSVCPASSWORD=`"$($SqlServerSvcPassword)`""
}
if ($AgtSvCPassword) {
$argumentList += " /AGTSVCPASSWORD=`"$($AgtSvCPassword)`""
}
Start-Process -Wait -FilePath $setupPath -ArgumentList $argumentList -RedirectStandardOutput setup-output.txt
Dismount-DiskImage -ImagePath $imagePath | Out-Null
@@ -213,16 +209,17 @@ try {
write-host "==== Install SQL Arc extension with LT=PAYG and upgrade to the latest version ===="
$extensionName = "WindowsAgent.SqlServer"
$Settings = @{
SqlManagement = @{ IsEnabled = $true };
LicenseType = "PAYG";
enableExtendedSecurityUpdates = $False;
esuLastUpdatedTimestamp = [DateTime]::UtcNow.ToString('yyyy-MM-ddTHH:mm:ss.fffZ')
}
New-AzConnectedMachineExtension -ResourceGroupName $AzureResourceGroup -MachineName $hostName -Name "Microsoft.AzureData" -Publisher "Microsoft.AzureData" -ExtensionType "WindowsAgent.SqlServer" -Location $AzureRegion -Settings $Settings -EnableAutomaticUpgrade
# Step 10: Display the status of the Azure resource for Arc-enabled SQL Server
New-AzConnectedMachineExtension -ResourceGroupName $AzureResourceGroup -MachineName $hostName -Name "WindowsAgent.SqlServer" -Publisher "Microsoft.AzureData" -ExtensionType "WindowsAgent.SqlServer" -Location $AzureRegion -Settings $Settings -EnableAutomaticUpgrade
write-host "==== Display the status of the billable Arc-enabled host ===="
$query = "