none
Getting status of a VSTS test agent using powershell RRS feed

  • Question

  • Hi,

    Is it possible to get the status of a VSTS Test agent status "Online"/"Offline" from a remote agent machines? (Windows 7 VM machines)


    sekhar


    • Edited by RAVISANGAM Thursday, July 12, 2018 9:54 AM added more info
    • Moved by Bill_Stewart Tuesday, December 11, 2018 8:51 PM Off-topic
    Thursday, July 12, 2018 9:53 AM

All replies

  • I would post in the Visual Studio forum for this question.


    \_(ツ)_/

    Thursday, July 12, 2018 10:06 AM
  • This link is having rest api for TFS and no information about lab management is provided.

    sekhar

    Thursday, July 12, 2018 11:06 AM
  • Here is the home of VSTS forum: https://stackoverflow.com/questions/tagged/vsts


    \_(ツ)_/

    Thursday, July 12, 2018 11:27 AM
  • Here are the only commands available for VSTS: http://www.donovanbrown.com/post/PowerShell-I-would-like-you-to-meet-TFS-and-VSTS


    \_(ツ)_/

    Thursday, July 12, 2018 11:33 AM
  • I am able to get the status of a test agent using c# code. But i am getting errors when i tried to call that c# code in powershell. Can i post my code here?

    sekhar

    Thursday, July 12, 2018 12:23 PM
  • You can if it is not too long.


    \_(ツ)_/

    Thursday, July 12, 2018 12:43 PM
  • $url = "https://tfs.xxxxxxxxxxx.com/tfs/DefaultCollection"

    $Source = @"
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.Lab.Client;

    using System;
    using System.Collections.Generic;

    namespace TFS{

        public class AgentStatus
        {
            public static void Get()
            {
                TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri($url));
                var _lab = (LabService)tpc.GetService(typeof(LabService));
                var labQuerySpec = new LabEnvironmentQuerySpec { Project = "Test" };

                ICollection<LabEnvironment> labs = _lab.QueryLabEnvironments(labQuerySpec);
                foreach (var labEnv in labs)
                {
                    if (labEnv.Name == "agent1")
                    {
                        var status = labEnv.StatusInfo.State.ToString();
                    }
                }

                Console.WriteLine(status);
            }
        }
    }
    "@

    Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Client.dll"

    Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Lab.Client.dll"

    Add-Type -TypeDefinition $Source -Language CSharp  

    $x = [TFS.AgentStatus]::Get()

    Write-Host $x

    And the error i am getting is 

    Add-Type : c:\Users\sekhar\AppData\Local\Temp\axvqeord\axvqeord.0.cs(1) : The type or namespace name 'TeamFoundation' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    c:\Users\sekhar\AppData\Local\Temp\axvqeord\axvqeord.0.cs(1) : >>> using Microsoft.TeamFoundation.Client;
    c:\Users\sekhar\AppData\Local\Temp\axvqeord\axvqeord.0.cs(2) : using Microsoft.TeamFoundation.Lab.Client;
    At line:44 char:1
    + Add-Type -TypeDefinition $Source -Language CSharp
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (c:\Users\sekhar...bly reference?):CompilerError) [Add-Type], Exception
        + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
     

    sekhar



    • Edited by RAVISANGAM Thursday, July 12, 2018 1:17 PM
    Thursday, July 12, 2018 1:14 PM