Azure-sql-performance: Module 5 failing, no $location found/set

Scott 0 Reputation points
2024-05-29T19:18:47.53+00:00

Module Link:

https://learn.microsoft.com/en-us/training/modules/azure-sql-performance/5-exercise-monitor-troubleshoot-performance

Running the following script FAILS: No $location found:

=======================================

$adminSqlLogin = "cloudadmin"

$password = Read-Host "Your username is 'cloudadmin'. Please enter a password for your Azure SQL Database server that meets the password requirements"

Prompt for local ip address

$ipAddress = Read-Host "Disconnect your VPN, open PowerShell on your machine and run '(Invoke-WebRequest -Uri "https://ipinfo.io/ip").Content'. Please enter the value (include periods) next to 'Address':"

Get resource group and location and random string

$resourceGroup = Get-AzResourceGroup | Where ResourceGroupName -like "Sandbox resource group name"

$resourceGroupName = "Sandbox resource group name"

$uniqueID = Get-Random -Minimum 100000 -Maximum 1000000

$storageAccountName = "mslearnsa"+$uniqueID

$location = $resourceGroup.Location

$serverName = "aw-server$($uniqueID)"

===================

OUTPUT FROM SCRIPT:

Your username is 'cloudadmin'. Please enter a password for your Azure SQL Database server that meets the password requirements: Longsh0t!

PS /home/azure> # Prompt for local ip address

PS /home/azure> $ipAddress = Read-Host "Disconnect your VPN, open PowerShell on your machine and run '(Invoke-WebRequest -Uri "https://ipinfo.io/ip").Content'. Please enter the value (include periods) next to 'Address':"

Disconnect your VPN, open PowerShell on your machine and run '(Invoke-WebRequest -Uri https://ipinfo.io/ip).Content'. Please enter the value (include periods) next to 'Address':: 184.101.187.188

PS /home/azure> # Get resource group and location and random string

PS /home/azure> $resourceGroup = Get-AzResourceGroup | Where ResourceGroupName -like "Sandbox resource group name"

PS /home/azure> $resourceGroupName = "Sandbox resource group name"

PS /home/azure> $uniqueID = Get-Random -Minimum 100000 -Maximum 1000000

PS /home/azure> $storageAccountName = "mslearnsa"+$uniqueID

PS /home/azure> $location = $resourceGroup.Location

PS /home/azure> $serverName = "aw-server$($uniqueID)"

PS /home/azure> Write-Host "Please note your unique ID for future exercises in this module:"

Please note your unique ID for future exercises in this module:

PS /home/azure> Write-Host $uniqueID

181735

PS /home/azure> Write-Host "Your resource group name is:"

Your resource group name is:

PS /home/azure> Write-Host $resourceGroupName

Sandbox resource group name

PS /home/azure> Write-Host "Your resources were deployed in the following region:"

Your resources were deployed in the following region:

PS /home/azure> Write-Host $location #MISSING! NOT FOUND!!!

PS /home/azure> Write-Host "Your server name is:"

Your server name is:

PS /home/azure> Write-Host $serverName

aw-server181735

PS /home/azure>

This question is related to the following Learning Module

Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop new skills.
1,184 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SiddeshTN 3,275 Reputation points Microsoft Vendor
    2024-06-01T18:06:00.0466667+00:00

    Hi Scott,

    Thank you for your response.

    Since we can't control the resource group name and the $location variable is coming up as null.

    Step-by-Step Troubleshooting and Fixing:

    1.To verify that the resource group exists and is named correctly, please use the following command to list all resource groups in your Azure subscription:

    Get-AzResourceGroup
    

    Check if there is a resource group that matches the name "Sandbox resource group name". If there isn't, you might need to create it or use an existing resource group.

    2.Please follow the script to handle cases where the resource group is not found. Here is an updated version of the script:

    $adminSqlLogin = "cloudadmin"
    $password = Read-Host "Your username is 'cloudadmin'. Please enter a password for your Azure SQL Database server that meets the password requirements"
    # Prompt for local IP address
    $ipAddress = Read-Host "Disconnect your VPN, open PowerShell on your machine and run '(Invoke-WebRequest -Uri ""https://ipinfo.io/ip"").Content'. Please enter the value (include periods) next to 'Address':"
    # Get resource group and location and random string
    $resourceGroup = Get-AzResourceGroup | Where-Object { $_.ResourceGroupName -like "Sandbox resource group name" }
    if ($null -eq $resourceGroup) {
        Write-Host "Resource group 'Sandbox resource group name' not found. Please ensure the resource group exists and try again."
        exit
    }
    $resourceGroupName = $resourceGroup.ResourceGroupName
    $location = $resourceGroup.Location
    $uniqueID = Get-Random -Minimum 100000 -Maximum 1000000
    $storageAccountName = "mslearnsa"+$uniqueID
    $serverName = "aw-server$($uniqueID)"
    Write-Host "Please note your unique ID for future exercises in this module:"
    Write-Host $uniqueID
    Write-Host "Your resource group name is:"
    Write-Host $resourceGroupName
    Write-Host "Your resources were deployed in the following region:"
    Write-Host $location
    Write-Host "Your server name is:"
    Write-Host $serverName
    

    3.If the resource group does not exist, please create it using the following command.

    New-AzResourceGroup -Name "Sandbox resource group name" -Location "YourPreferredLocation"
    

    Please replace "YourPreferredLocation" with the actual Azure region where you want to create the resource group (e.g., "East US", "West Europe").

    Next, please run the script again in Azure Cloud Shell. Ensure that the resource group exists, and the script is modified to handle potential null values.

    By verifying the existence of the resource group and handling null values in the script, you should be able to successfully retrieve the location and proceed with the deployment of the Azure SQL Database.

    If you have any other concerns, please let us know. We are here to help you.

    If the provided solution has resolved your issue, please click the "upvote" button to increase the visibility of this question for other members of the Microsoft Q&A community.

    Thank you.

    0 comments No comments