Skip to content

Instantly share code, notes, and snippets.

@TravisEz13
Last active April 17, 2019 17:08
Show Gist options
  • Save TravisEz13/a62cc109476176a97d182b6146694bf3 to your computer and use it in GitHub Desktop.
Save TravisEz13/a62cc109476176a97d182b6146694bf3 to your computer and use it in GitHub Desktop.
param(
[parameter(Mandatory)]
[string]$Url,
[parameter(Mandatory)]
[string]$Pat,
[parameter(Mandatory)]
[string]$Pool
)
$ErrorActionPreference = 'stop'
$agentZipUrl = 'https://vstsagentpackage.azureedge.net/agent/2.148.2/vsts-agent-win-x64-2.148.2.zip'
$installPsUrl = 'https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.ps1'
Invoke-WebRequest -Uri $installPsUrl -outFile ./install-powershell.ps1
./install-powershell.ps1 -AddToPath
Invoke-WebRequest -Uri $agentZipUrl -outFile ./agent.zip
Expand-Archive -Path ./agent.zip -DestinationPath C:\AzDevOpsAgent -force
$workDir = 'C:\1'
$null = New-Item -ItemType Directory -Path $workDir
Write-Host "Url: $Url"
Write-Host "Pool: $pool"
C:\AzDevOpsAgent\config.cmd --unattended --url $Url --auth pat --token $Pat --pool $Pool --agent $env:Computername --work $workDir --runAsService
@adityapatwardhan
Copy link

Line # 21 should be changed to the following as Expand-Archive is not supported on Windows PowerShell version below 5.0.

[System.IO.Compression.ZipFile]::ExtractToDirectory("./agent.zip", "C:\AzDevOpsAgent")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment