Last active
May 4, 2020 19:29
-
-
Save igoravl/dbd6b901196e9b1d60da65a3d4089904 to your computer and use it in GitHub Desktop.
Install Azure DevOps Deployment Agent (off-line)
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 ( | |
[string] | |
$AgentZip = 'agent.zip', | |
[string] | |
$AgentDirectory = "$($env:SystemDrive\Agent)", | |
[Parameter(Mandatory=$true)] | |
[string] | |
$DeploymentPoolName, | |
[string] | |
$AgentName = $env:COMPUTERNAME, | |
[string] | |
$WorkFolder = '_work', | |
[Parameter(Mandatory=$true)] | |
[string] | |
$OrganizationUrl, | |
[Parameter(Mandatory=$true)] | |
[string] | |
$PersonalAccessToken | |
) | |
Function Test-IsAdmin { | |
$identity = [Security.Principal.WindowsIdentity]::GetCurrent() | |
$principal = New-Object Security.Principal.WindowsPrincipal $identity | |
$principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
} | |
If (-not (Test-IsAdmin)) { | |
throw "Run command in an administrator PowerShell prompt" | |
} | |
If ($PSVersionTable.PSVersion -lt ([version]"3.0")) | |
{ | |
throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell ($($PSVersionTable.PSVersion))" | |
} | |
If (-not (Test-Path $AgentDirectory)) | |
{ | |
New-Item $AgentDirectory -ItemType Directory | Out-Null | |
} | |
Try | |
{ | |
Push-Location $AgentDirectory | |
for ($i = 1; $i -lt 100; $i++) | |
{ | |
$destFolder = (Join-Path $AgentDirectory "A$i") | |
if(Test-Path $destFolder) | |
{ | |
continue | |
} | |
New-Item $destFolder -ItemType Directory | Out-Null | |
Push-Location $destFolder | |
} | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
[System.IO.Compression.ZipFile]::ExtractToDirectory( $AgentZip, "$PWD") | |
.\config.cmd --deploymentpool --deploymentpoolname $DeploymentPoolName --agent $AgentName --runasservice --work $WorkFolder --url $OrganizationUrl --auth PAT --token $PersonalAccessToken | |
Pop-Location | |
} | |
finally | |
{ | |
Pop-Location | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment