Skip to content

Instantly share code, notes, and snippets.

@Antebios
Created October 22, 2021 16:04
Show Gist options
  • Save Antebios/ef8a4e75941a977a0a997da5c936b471 to your computer and use it in GitHub Desktop.
Save Antebios/ef8a4e75941a977a0a997da5c936b471 to your computer and use it in GitHub Desktop.
Install Azure DevOps Agent Silently
[CmdletBinding()]
param(
[Parameter(Mandatory=$false)]
[string]$AgentDirectory="C:\ADO-Agent1",
[Parameter(Mandatory=$false)]
[string]$OrganizationName="some-org-name",
[Parameter(Mandatory=$true)]
[string]$PAT,
[Parameter(Mandatory=$true)]
[string]$Pool,
[Parameter(Mandatory=$true)]
[string]$AgentName,
[Parameter(Mandatory=$true)]
[string]$ServiceAccountLogin
)
$AgentPacakageUrl='https://vstsagentpackage.azureedge.net/agent/2.188.3/vsts-agent-win-x64-2.188.3.zip'
[securestring]$ServiceAccountPassword = (
Read-Host -prompt "Enter password for service account $ServiceAccountLogin" -AsSecureString
)
# create directory
Write-Host "Creating Agent directory at: $AgentDirectory"
New-Item -ItemType Directory $AgentDirectory -Force | Write-Verbose
# download zip package
$AgentArchiveLocalPath=Join-Path $PSScriptRoot "vsts-agent.zip"
if (-Not(Test-Path $AgentArchiveLocalPath)) {
Invoke-WebRequest $AgentPacakageUrl -OutFile $AgentArchiveLocalPath
} else {
Write-Host "VSTS Agent already exists at: $AgentArchiveLocalPath"
Write-Host "Downloading of VSTS Agent is skipped."
}
# Unzip package
Write-Host "Expanding VSTS Agent to: $AgentDirectory"
Expand-Archive -Path $AgentArchiveLocalPath -DestinationPath $AgentDirectory
Set-Location "$AgentDirectory"
$pwd = [System.Net.NetworkCredential]::new('', $ServiceAccountPassword).Password
# Configure ADO Agent silently
& .\config.cmd --unattended --url https://dev.azure.com/$OrganizationName `
--auth pat --token $PAT --pool $Pool --agent $AgentName --replace `
--runAsService --windowsLogonAccount $ServiceAccountLogin --windowsLogonPassword $pwd
Write-Host "Completed the installation and configuration of the VSTS Agent, $AgentName, for the Pool, $Pool."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment