here is the script you can use to register/deregister ADO agents
PARAM( [int] $NoofAgents, [string] $vsts_url = "https://dev.azure.com/name", [string] $vsts_pat, [string] $svcUserName = "domain\user", [string] $svcPassword, [string] $agentAction ) $agent_pool = 'Poolname'; $ErrorActionPreference="Stop"; If(-NOT (Test-Path $env:SystemDrive\'agents')) {mkdir $env:SystemDrive\'agents'}; Cd $env:SystemDrive\'agents'; if($agentAction -eq "register"){ Write-Host "Download Agent Zip from ADO..." -NoNewline $agentZip="$PWD\agent.zip"; $DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy; $securityProtocol=@(); $securityProtocol+=[Net.ServicePointManager]::SecurityProtocol; $securityProtocol+=[Net.SecurityProtocolType]::Tls12; [Net.ServicePointManager]::SecurityProtocol=$securityProtocol; $WebClient=New-Object Net.WebClient; $Uri='https://vstsagentpackage.azureedge.net/agent/2.185.1/vsts-agent-win-x64-2.185.1.zip'; if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))) { $WebClient.Proxy= New-Object Net.WebProxy($DefaultProxy.GetProxy($Uri).OriginalString, $True); }; #$WebClient.DownloadFile($Uri, $agentZip); Write-Host "Done" for($i=1; $i -le $NoofAgents; $i++) { $destFolder="Agent_"+$('{0:d3}' -f [int]$i) Write-Host "$destFolder Operations..." if(-NOT (Test-Path ($destFolder))) { mkdir $destFolder | Out-null; Write-Host "`tExtracting Files...." -NoNewline Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory( $agentZip, "$PWD\$destFolder"); Write-Host "Installation......" -NoNewline $agentName = ("$($env:computername)_$($destFolder)_win").ToLower() Set-Location "$PWD\$destFolder" & .\config.cmd --unattended --url $vsts_url --auth pat --token $vsts_pat --pool $agent_pool --agent $agentName --windowsLogonAccount $svcUserName --windowsLogonPassword """$svcPassword""" --runAsService } Set-Location "c:\agents" }; } elseif ($agentAction -eq "deregister") { $agentList = Get-ChildItem -filter "agent*" -Directory | % {$_.Fullname} $agentList | %{ $path = $_ $destFolder = (Split-Path $path -Leaf ) Write-Host "Unregistering $($destFolder) ..." -NoNewline & $path\config.cmd remove --unattended --url $vsts_url --auth pat --token $vsts_pat --pool $agent_pool --agent "$($env:computername)_$($destFolder)_win" Remove-Item $Path -Recurse -Force Write-Host "Done" } }
- Get link
- X
- Other Apps
Labels
ado agent CodeSnippet DevOps powershell vsts
Labels:
ado
agent
CodeSnippet
DevOps
powershell
vsts
- Get link
- X
- Other Apps
Comments
Post a Comment