As a cloud enthusiast, I’ve crafted a PowerShell script that serves as a cornerstone for anyone looking to establish a dynamic lab environment in Azure. This script is not just a tool; it’s a gateway to a realm where testing, learning, and experimentation happen seamlessly. Hosted on GitHub within the “DeathStarScriptHub” repository, this script automates the setup of essential Azure resources, allowing you to focus on what truly matters – innovation and exploration.
The Essence of the Script
The script is designed to deploy a lab environment that can be easily spun up for testing and just as effortlessly disposed of. The script smartly appends the current date stamp to all deployed resources, ensuring each lab session remains unique and easily identifiable. This feature is particularly useful for tracking different experiments or test scenarios over time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#Createdby: Shaun Hardneck #www.thatlazyadmin.com # Connect to Azure account Connect-AzAccount # Get all available subscriptions $subscriptions = Get-AzSubscription # Display available subscriptions in orange and prompt for selection if ($subscriptions.Count -eq 0) { Write-Host "No Azure subscriptions are available." -ForegroundColor Red exit } Write-Host "Available Azure Subscriptions:" -ForegroundColor DarkYellow for ($i = 0; $i -lt $subscriptions.Count; $i++) { Write-Host "$($i + 1): $($subscriptions[$i].Name) - $($subscriptions[$i].Id)" -ForegroundColor DarkYellow } while ($true) { $selectedSubscriptionIndex = Read-Host "Select a subscription by entering a number (1-$($subscriptions.Count))" if ($selectedSubscriptionIndex -match '^\d+$' -and [int]$selectedSubscriptionIndex -gt 0 -and [int]$selectedSubscriptionIndex -le $subscriptions.Count) { $selectedSubscription = $subscriptions[[int]$selectedSubscriptionIndex - 1] Write-Host "You have selected the subscription: $($selectedSubscription.Name)" -ForegroundColor Green Set-AzContext -SubscriptionId $selectedSubscription.Id break } else { Write-Host "Invalid selection. Please enter a number between 1 and $($subscriptions.Count)." -ForegroundColor Red } } # Variables $location = "southafricanorth" $today = Get-Date -Format "yyyyMMdd" $resourceGroupName = "thatlazyadminLab-$today" $virtualNetworkName = "thatlazyadminVNet-$today" $subnetName = "thatlazyadminSubnet" $nsgName = "thatlazyadminNSG-$today" $adminUsername = "adminuser" $adminPassword = ConvertTo-SecureString "Password123!" -AsPlainText -Force $vmSize = "Standard_B1s" $image = "MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest" $openPorts = @(80, 3389) |
Deployed Resources
The script meticulously sets up the following resources, providing a solid foundation for a wide range of lab activities:
- Resource Group: Serves as a logical container for organizing the Azure resources deployed for your lab session.
- Virtual Network and Subnet: Creates the backbone of your lab’s network, enabling you to simulate various networking scenarios.
- Network Security Group: Implements basic security rules, blocking common ports like 80 and 443 to ensure a secure initial setup.
- Virtual Machines: Deploys two Windows Server 2022 instances, ready to be moulded to your testing requirements.
Leveraging the Script
- Getting Started:
- Ensure you have an Azure subscription and the Azure PowerShell module ready.
- Download the script from the provided GitHub link.
- Running the Script:
- Open PowerShell, navigate to the script’s location, and execute it. The script will guide you through the Azure authentication process and subscription selection.
- Customization and Flexibility:
- Tailor the script to your needs by adjusting parameters such as resource names, VM sizes, and network configurations.
- Post-Deployment Exploration:
- With the lab environment in place, the real adventure begins. Whether it’s networking, server management, or security, the lab is your sandbox.
Why This Script?
I created this lab script out of a necessity to have a flexible, repeatable, and disposable testing ground in Azure. The inclusion of the current date stamp in resource names is a deliberate choice to facilitate easy identification and management of multiple lab instances over time. Whether you’re testing a new software, studying for a certification, or demonstrating a scenario, this script ensures your lab environment is just a few commands away.
The following resource are deployed after successful execution:
In Conclusion
This PowerShell script is more than just automation; it’s about empowering you to test, learn, and innovate in Azure without the overhead of manual setup. It’s about making each lab session meaningful, manageable, and, most importantly, focused on your learning objectives. Dive in, experiment, and when the time comes, dispose and start anew, all with the confidence that setting up your next lab is just a script execution away.
Embrace the power of automation and let your cloud journey be boundless. Happy experimenting!
Be First to Comment