MSLab.psm1
function Get-MSLabReleases { $r = Invoke-RestMethod -UseBasicParsing -Uri "https://api.github.com/repos/microsoft/mslab/releases" $r | Sort-Object published_at | Select-Object @{ Name="version"; Expression={ $_.'tag_name' } }, created_at, prerelease } function Initialize-MSLabFolder { [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = 'High')] param( $Version = "latest", $Destination = (Get-Location).Path ) if ($PSCmdlet.ShouldProcess($Destination)) { $r = Invoke-RestMethod -UseBasicParsing -Uri "https://api.github.com/repos/microsoft/mslab/releases/$($Version)" $link = $r.assets | Select-Object -First 1 -ExpandProperty browser_download_url $temporaryPath = New-TemporaryFile Invoke-WebRequest -Uri $link -OutFile "$($temporaryPath.FullName).zip" Expand-Archive -Path "$($temporaryPath.FullName).zip" -DestinationPath $Destination Remove-Item -path "$($temporaryPath.FullName).zip" -force } } function Update-MSLabLinuxTemplates { $packerTemplatesDirectory = "$PSScriptRoot\ParentDisks\PackerTemplates\" if (-not (Test-Path $packerTemplatesDirectory)) { "Packer templates directory does not exist." return } $templatesBase = "https://github.com/microsoft/mslab-templates/releases/latest/download/" $templatesFile = "$($packerTemplatesDirectory)\templates.json" #$current = Get-Content $templatesFile | ConvertFrom-Json #"Current version: $($current.version)" Invoke-WebRequest -Uri "$($templatesBase)/templates.json" -OutFile $templatesFile if(-not (Test-Path -Path $templatesFile)) { "Download of Packer templates failed" return } $templatesInfo = Get-Content -Path $templatesFile | ConvertFrom-Json foreach($template in $templatesInfo.templates) { " * $($template.package)" $templateDestinationPath = (Join-Path $packerTemplatesDirectory $template.directory) if(Test-Path -Path $templateDestinationPath) { Remove-Item -Force -Recurse -Path $templateDestinationPath } $templateZipFile = Join-Path $packerTemplatesDirectory $template.package Invoke-WebRequest -Uri "$($templatesBase)/$($template.package)" -OutFile $templateZipFile Expand-Archive -Path $templateZipFile -DestinationPath $templateDestinationPath Remove-Item -Path $templateZipFile } $current = Get-Content $templatesFile | ConvertFrom-Json "Downloaded version: $($current.version)" } |