Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Creates a new Lability Environment for an Azure DevOps build agent
[parameter(Mandatory = $true, HelpMessage = "Admin user name for new VM")]
[parameter(Mandatory = $true, HelpMessage = "Admin passworduser name for new VM")]
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps PAT token")]
[parameter(Mandatory = $true, HelpMessage = "URL of Azure DevOps instance t register agent on e.g.")]
$url ,
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps Agent Pool name")]
$pool ,
[parameter(Mandatory = $true, HelpMessage = "Based name for lability defintion")]
[parameter(Mandatory = $true, HelpMessage = "Prefix for envioment name")]
[parameter(Mandatory = $true, HelpMessage = "Index of prefix and used to calculate IP address")]
# make sure get-psreposity is available
# Upgrade PowerShellGet
Install-Module PowerShellGet -Force -repository 'PSGallery'
Remove-Module PowerShellGet -Force
Import-Module PowerShellGet -Force
if(!(Get-module Lability )) {
Import-Module Lability
write-host "Set the VM details Prefix $prefix$index"
$subnet = "192.168.$(255-$index).0/24"
$settingsoverride = @{AzureDevOps = @{Url = $url;Pool = $pool;Pat = $pat}}
$AgentPassword = ConvertTo-SecureString -String $AgentPassword -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($AgentUser, $AgentPassword)
# wrapper for Lability command. Execute the Start-LabConfiguration command passing in the configuration data file.
Add-VmcLab -Environment $environmentName -Credential $cred -Prefix $prefix$index -SettingOverride $settingsoverride -subnet $subnet -start -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment