0

enter image description here

I am trying to install the VSTS build agent on a Windows Server 2016 using the below Powershell script but the script fails with the below error.

$tfsUrl=”http://vwmaztfsapp:8080/tfs/Collection”
$pool = ”Cli Execution”
$username = ”dev.local\svc_tfsAcc”
$password = ”MyPassword”
$AgentName = "Aut1"


CD "$AgentFolder\vsts-agent-win7-x64-2.122.1-Aut6\"

# configure agent to run as a Windows service that logs on as a domain account
& .\config.cmd --unattended -–url "$tfsUrl" --auth "integrated" -–pool "$pool" -–agent "$AgentName" --work "$AgentFolder\$AgentName" –-runAsService -–windowsLogonAccount "$username" –-windowsLogonPassword "$password"

Error below -

PS C:\Agents\vsts-agent-win7-x64-2.122.1-Aut6> C:\Agents\vsts-agent-win7-x64-2.122.1-Aut6\InstallAgent.ps1
config.cmd : Unrecognized command-line input arguments: 'unattended'. For usage refer to: .\config.cmd --help or ./config.sh --help
At C:\Agents\vsts-agent-win7-x64-2.122.1-Aut6\InstallAgent.ps1:49 char:1
+ & .\config.cmd --unattended -–url "$tfsUrl" --auth "integrated" -–poo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Unrecognized co...onfig.sh --help:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Is there something that I am missing? I need to install the agent on multiple servers and that's the reason I want to automate this process.

SRP
  • 999
  • 4
  • 21
  • 39
  • The command is telling you that the `--unattended` flag is invalid. Did do what the error message suggested and look at the supported parameters with `--help`? – Daniel Mann Mar 30 '20 at 18:58
  • @Daniel, I searched it yesterday itself and the --unattended command is the correct as per syntax. I unable to understand why it is throwing the error. I will check if i can attach a screenshot of the same. – SRP Mar 31 '20 at 08:21
  • @SRP if you try to install it with `--unattended` in CMD directly (not with PS script) is it works? – Shayki Abramczyk Mar 31 '20 at 08:29
  • Yes, it works. I just tried now by copying the code in cmd and passed the value directly on cmd and it successfully created the agent in TFS why does it doesn't work with Powershell then, not even with elevated Powershell. – SRP Mar 31 '20 at 11:45

1 Answers1

0

Update

n

I was using command without "" such as:

.\config.cmd --unattended --url https://dev.azure.com/patricklu2020 --auth pat --token n2upx6epgl4srovzgp6is5wytjfkspvv6uvxxxx --pool default --agent myAgent --work D:\agent_work

If you want to configure as a service, you need to configure the agent from an elevated PowerShell window, this is required.

I would suggest you directly run the command from an elevated powershell window first, and then check if you are able to configure the agent correctly.

This kind of error maybe caused by passing arguments incorrectly. Kindly verify it.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • It doesn't work with elevated powershell like it worked on CMD prompt. It elevated powershell it agained asked for enter URL even after i gave the url in the command itself. On cmd the same command worked smoothly. Adding screenshot at the top for reference. – SRP Mar 31 '20 at 12:12
  • @SRP This is wired. It worked well with powershell in my environment. Please check my update screenshot. By the way, I am on the version 5.1.18362.628. After more investigation with comparing your command. I found the only difference is that I was using the command without `" "` of the value. Please also give a try on it in your side. – PatrickLu-MSFT Apr 01 '20 at 10:50
  • I tried the command without " " but still gave me the same error present in the screenshot. my PS version is 5.1.17763.1007 – SRP Apr 02 '20 at 06:33
  • @SRP Do you have any Azure DevOps Service account? I would suggest you also give a try with using similar command include `--unattended` to configure a self-host agent on Azure DevOps Service. If it works in same environment on your side. I am afraid, the only reason rest -- this is not support on TFS server 2017. – PatrickLu-MSFT Apr 02 '20 at 10:09