Last active
December 9, 2025 15:04
-
-
Save raandree/c6ef32777eaab1591d3ae9e14dc6e1d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Mandatory = $false)] | |
| [string]$Version | |
| ) | |
| # First do the standard installation | |
| Write-Host "========================================" -ForegroundColor Cyan | |
| Write-Host "AutomatedLab Installation Script" -ForegroundColor Cyan | |
| Write-Host "========================================" -ForegroundColor Cyan | |
| Write-Host "" | |
| if ($Version) { | |
| Write-Host "Target Version: $Version" -ForegroundColor Cyan | |
| Write-Host " Checking if version exists..." -ForegroundColor Gray | |
| try { | |
| $availableModule = Find-Module -Name AutomatedLab -RequiredVersion $Version -AllowPrerelease -ErrorAction Stop | |
| Write-Host " ✓ Version $Version found" -ForegroundColor Green | |
| } | |
| catch { | |
| Write-Host " ✗ Version $Version not found" -ForegroundColor Red | |
| Write-Host "" | |
| Write-Host "Available versions (including pre-releases):" -ForegroundColor Yellow | |
| try { | |
| $allVersions = Find-Module -Name AutomatedLab -AllVersions -AllowPrerelease | Select-Object -First 10 Version | |
| $allVersions | ForEach-Object { Write-Host " - $($_.Version)" -ForegroundColor Gray } | |
| } | |
| catch { | |
| Write-Host " Unable to retrieve available versions" -ForegroundColor Red | |
| } | |
| exit 1 | |
| } | |
| Write-Host "" | |
| } | |
| Write-Host "[Step 1/2] Installing AutomatedLab meta-module..." -ForegroundColor Yellow | |
| Write-Host " This may take a few minutes..." -ForegroundColor Gray | |
| try { | |
| if ($Version) { | |
| Install-Module -Name AutomatedLab -RequiredVersion $Version -AllowPrerelease -AllowClobber -Force -Scope AllUsers -ErrorAction Stop | |
| } | |
| else { | |
| Install-Module -Name AutomatedLab -AllowPrerelease -AllowClobber -Force -Scope AllUsers -ErrorAction Stop | |
| } | |
| Write-Host " ✓ AutomatedLab meta-module installed successfully" -ForegroundColor Green | |
| } | |
| catch { | |
| Write-Host " ✗ Failed to install AutomatedLab: $($_.Exception.Message)" -ForegroundColor Red | |
| exit 1 | |
| } | |
| Write-Host "" | |
| $modules = @( | |
| 'AutomatedLab.Common', | |
| 'AutomatedLab.Recipe', | |
| 'AutomatedLab.Ships', | |
| 'AutomatedLabCore', | |
| 'AutomatedLabDefinition', | |
| 'AutomatedLabNotifications', | |
| 'AutomatedLabTest', | |
| 'AutomatedLabUnattended', | |
| 'AutomatedLabWorker', | |
| 'HostsFile', | |
| 'PSFileTransfer', | |
| 'PSLog' | |
| ) | |
| $path = if ($PSVersionTable.PSEdition -eq 'Core') | |
| { | |
| "$env:ProgramFiles\PowerShell\Modules" | |
| } | |
| else | |
| { | |
| "$env:ProgramFiles\WindowsPowerShell\Modules" | |
| } | |
| Write-Host "[Step 2/2] Updating AutomatedLab component modules to latest versions..." -ForegroundColor Yellow | |
| Write-Host " Target Path: $path" -ForegroundColor Gray | |
| Write-Host " Modules to update: $($modules.Count)" -ForegroundColor Gray | |
| Write-Host "" | |
| $successCount = 0 | |
| $failureCount = 0 | |
| foreach ($module in $modules) | |
| { | |
| Write-Host " Processing: " -NoNewline -ForegroundColor Gray | |
| Write-Host "$module" -NoNewline -ForegroundColor White | |
| Write-Host "..." -ForegroundColor Gray | |
| try { | |
| # AutomatedLab.Common always uses its own latest version | |
| if ($module -eq 'AutomatedLab.Common') { | |
| Save-Module -Name $module -Path $path -Force -AllowPrerelease -ErrorAction Stop | |
| } | |
| elseif ($Version) { | |
| Save-Module -Name $module -Path $path -RequiredVersion $Version -AllowPrerelease -Force -ErrorAction Stop | |
| } | |
| else { | |
| Save-Module -Name $module -Path $path -Force -AllowPrerelease -ErrorAction Stop | |
| } | |
| Write-Host " ✓ " -NoNewline -ForegroundColor Green | |
| Write-Host "$module updated successfully" -ForegroundColor Gray | |
| $successCount++ | |
| } | |
| catch { | |
| Write-Host " ✗ " -NoNewline -ForegroundColor Red | |
| Write-Host "Failed to update $module : $($_.Exception.Message)" -ForegroundColor Red | |
| $failureCount++ | |
| } | |
| } | |
| Write-Host "" | |
| Write-Host "========================================" -ForegroundColor Cyan | |
| Write-Host "Installation Summary" -ForegroundColor Cyan | |
| Write-Host "========================================" -ForegroundColor Cyan | |
| Write-Host "Total Modules Processed: " -NoNewline -ForegroundColor White | |
| Write-Host "$($modules.Count)" -ForegroundColor Cyan | |
| Write-Host "Successfully Updated: " -NoNewline -ForegroundColor White | |
| Write-Host "$successCount" -ForegroundColor Green | |
| Write-Host "Failed: " -NoNewline -ForegroundColor White | |
| Write-Host "$failureCount" -ForegroundColor $(if ($failureCount -eq 0) { "Green" } else { "Red" }) | |
| Write-Host "" | |
| if ($failureCount -eq 0) { | |
| Write-Host "✓ AutomatedLab installation completed successfully!" -ForegroundColor Green | |
| Write-Host "" | |
| Write-Host "Next Steps:" -ForegroundColor Yellow | |
| Write-Host " 1. Run 'New-LabSourcesFolder' to set up lab sources directory" -ForegroundColor Gray | |
| Write-Host " 2. Download required ISOs to the lab sources folder" -ForegroundColor Gray | |
| Write-Host " 3. Execute lab deployment scripts from the DscWorkshop\Lab folder" -ForegroundColor Gray | |
| } | |
| else { | |
| Write-Host "⚠ Installation completed with errors. Please review the output above." -ForegroundColor Yellow | |
| } | |
| Write-Host "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment