Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates a new Lability Environment for an Azure DevOps build agent
param
(
[parameter(Mandatory = $true, HelpMessage = "Admin user name for new VM")]
$AgentUser,
[parameter(Mandatory = $true, HelpMessage = "Admin passworduser name for new VM")]
$AgentPassword,
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps PAT token")]
$pat,
[parameter(Mandatory = $true, HelpMessage = "URL of Azure DevOps instance t register agent on e.g. https://dev.aure.com/myinstance")]
$url ,
[parameter(Mandatory = $true, HelpMessage = "Azure DevOps Agent Pool name")]
$pool ,
[parameter(Mandatory = $true, HelpMessage = "Based name for lability defintion")]
$environmentName,
[parameter(Mandatory = $true, HelpMessage = "Prefix for envioment name")]
$prefix,
[parameter(Mandatory = $true, HelpMessage = "Index of prefix and used to calculate IP address")]
$index
)
# 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
You can’t perform that action at this time.