Last active
January 6, 2020 14:17
-
-
Save rfennell/fb19cb0cd4c6dbd32d041b020a237093 to your computer and use it in GitHub Desktop.
Creates a new Lability Environment for an Azure DevOps build agent
This file contains 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
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