XamlBuild/XamlBuild.psm1

<#

.SYNOPSIS
    Gets information about one or more XAML Build agents.

.PARAMETER Collection
    
    Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.

    When using a URL, it must be fully qualified. The format of this string is as follows:

    http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>

    Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.

    To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.

    For more details, see the Get-TfsTeamProjectCollection cmdlet.


#>

Function Get-TfsXamlBuildAgent
{
    [CmdletBinding()]
    [OutputType([Microsoft.TeamFoundation.Build.Client.IBuildAgent])]
    Param
    (
        [Parameter(Position=0)]
        [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildAgent]})]
        [ValidateNotNullOrEmpty()]
        [Alias("Name")]
        [object] 
        $BuildAgent = "*",

        [Parameter(Position=0, ValueFromPipeline=$true)]
        [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildController]})]
        [ValidateNotNullOrEmpty()]
        [Alias("Controller")]
        [object] 
        $BuildController = "*",

        [Parameter()]
        [object]
        $Collection
    )

    Process
    {
        if ($BuildAgent -is [Microsoft.TeamFoundation.Build.Client.IBuildAgent])
        {
            return $BuildAgent
        }

        $controllers = Get-TfsXamlBuildController -BuildController $BuildController -Collection $Collection

        foreach($controller in $controllers)
        {
            $controller.Agents | Where Name -Like $BuildAgent
        }        
    }
}
<#

.SYNOPSIS
    Gets information about one or more XAML Build controllers.

.PARAMETER Collection
    
    Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.

    When using a URL, it must be fully qualified. The format of this string is as follows:

    http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>

    Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.

    To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.

    For more details, see the Get-TfsTeamProjectCollection cmdlet.


#>

Function Get-TfsXamlBuildController
{
    [CmdletBinding()]
    [OutputType([Microsoft.TeamFoundation.Build.Client.IBuildController])]
    Param
    (
        [Parameter(Position=0)]
        [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildController]})]
        [ValidateNotNullOrEmpty()]
        [Alias("Name")]
        [object] 
        $BuildController = "*",

        [Parameter(ValueFromPipeline=$true)]
        [object]
        $Collection
    )

    Process
    {
        if ($BuildController -is [Microsoft.TeamFoundation.Build.Client.IBuildController])
        {
            return $BuildController

        }

        $tpc = Get-TfsTeamProjectCollection $Collection

        $buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer')
        $buildControllers = $buildServer.QueryBuildControllers()
        
        return $buildControllers | Where Name -Like $BuildController
    }
}
<#

.SYNOPSIS
    Gets one or more XAML Build definitions.

.PARAMETER BuildDefinition
    Uses this parameter to filter for an specific Build Defintion.
    If suppress, cmdlet will show all queue builds.

.PARAMETER Project
    
    Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).

    For more details, see the Get-TfsTeamProject cmdlet.


.PARAMETER Collection
    
    Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.

    When using a URL, it must be fully qualified. The format of this string is as follows:

    http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>

    Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.

    To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.

    For more details, see the Get-TfsTeamProjectCollection cmdlet.


.EXAMPLE
    Get-TfsBuildQueue -BuildDefinition "My Build Definition" -Project "My Team Project"
    Get all queued builds given a definition name and a team project name

.EXAMPLE
    Get-TfsBuildQueue
    Get all queued builds, regardless of definition name or team project name

#>

Function Get-TfsXamlBuildDefinition
{
    [CmdletBinding()]
    [OutputType([Microsoft.TeamFoundation.Build.Client.IBuildDefinition])]
    Param
    (
        [Parameter(Position=0)]
        [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]})]
        [ValidateNotNullOrEmpty()]
        [Alias("Name")]
        [object] 
        $BuildDefinition = "*",

        [Parameter(ValueFromPipeline=$true)]
        [object]
        $Project,

        [Parameter()]
        [object]
        $Collection
    )

    Process
    {
        if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition])
        {
            return $BuildDefinition
        }

        $tp = Get-TfsTeamProject $Project $Collection
        $tpName = $tp.Name
        $tpc = $tp.Store.TeamProjectCollection

        $buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer')
        $buildDefs = $buildServer.QueryBuildDefinitions($tpName)
        
        return $buildDefs | Where Name -Like $BuildDefinition
    }
}
<#

.SYNOPSIS
    Gets information about queued XAML Builds.

.PARAMETER BuildDefinition
    Uses this parameter to filter for an specific Build Defintion.
    If suppress, cmdlet will show all queue builds.

.PARAMETER Project
    
    Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).

    For more details, see the Get-TfsTeamProject cmdlet.


.PARAMETER Collection
    
    Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.

    When using a URL, it must be fully qualified. The format of this string is as follows:

    http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>

    Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.

    To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.

    For more details, see the Get-TfsTeamProjectCollection cmdlet.


.EXAMPLE
    Get-TfsBuildQueue -BuildDefinition "My Build Definition" -Project "My Team Project"
    Get all queued builds given a definition name and a team project name

.EXAMPLE
    Get-TfsBuildQueue
    Get all queued builds, regardless of definition name or team project name

#>

Function Get-TfsXamlBuildQueue
{
    [CmdletBinding()]
    [OutputType([Microsoft.TeamFoundation.Build.Client.IQueuedBuild])]
    Param
    (
        [Parameter(Position=0, ValueFromPipeline=$true)]
        [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]})]
        [ValidateNotNullOrEmpty()]
        [object] 
        $BuildDefinition = "*",

        [Parameter()]
        [object]
        $Project,

        [Parameter()]
        [object]
        $Collection
    )

    Process
    {
        if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition])
        {
            $buildDefName = $BuildDefinition.Name
        }
        else
        {
            $buildDefName = $BuildDefinition
        }

        if ($Project)
        {
            $tp = Get-TfsTeamProject $Project $Collection
            $tpName = $tp.Name
            $tpc = $tp.Store.TeamProjectCollection
        }
        else
        {
            $tpName = "*"
            $tpc = Get-TfsTeamProjectCollection $Collection
        }

        $buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer')
        $query = $buildServer.CreateBuildQueueSpec($tpName, $buildDefName)
        
        $buildServer.QueryQueuedBuilds($query).QueuedBuilds
    }
}
<#

.SYNOPSIS
    Queues a XAML Build.

.PARAMETER BuildDefinition
    Build Definition Name that you want to queue.

.PARAMETER Project
    
    Specifies either the name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to. If omitted, it defaults to the connection opened by Connect-TfsTeamProject (if any).

    For more details, see the Get-TfsTeamProject cmdlet.


.PARAMETER Collection
    
    Specifies either a URL/name of the Team Project Collection to connect to, or a previously initialized TfsTeamProjectCollection object.

    When using a URL, it must be fully qualified. The format of this string is as follows:

    http[s]://<ComputerName>:<Port>/[<TFS-vDir>/]<CollectionName>

    Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS.

    To connect to a Team Project Collection by using its name, a TfsConfigurationServer object must be supplied either via -Server argument or via a previous call to the Connect-TfsConfigurationServer cmdlet.

    For more details, see the Get-TfsTeamProjectCollection cmdlet.


.EXAMPLE
    Start-TfsBuild -BuildDefinition "My Build Definition" -Project "MyTeamProject"
    This example queue a Build Definition "My Build Definition" of Team Project "MyTeamProject".

#>

Function Start-TfsXamlBuild
{
    Param
    (
        [Parameter(Mandatory=$true, Position=0)]
        [object] 
        $BuildDefinition,

        [Parameter(ValueFromPipeline=$true, Mandatory=$true)]
        [object]
        [ValidateNotNull()]
        [ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.WorkItemTracking.Client.Project])})] 
        $Project,

        [Parameter()]
        [object]
        $Collection,

        [Parameter()]
        [string]
        [ValidateSet("LatestOnQueue", "LatestOnBuild", "Custom")]
        $GetOption = "LatestOnBuild",

        [Parameter()]
        [string]
        $GetVersion,

        [Parameter()]
        [string]
        $DropLocation,

        [Parameter()]
        [hashtable]
        $Parameters
    )

    Process
    {

        $tp = Get-TfsTeamProject $Project $Collection
        $tpc = $tp.Store.TeamProjectCollection

        $buildServer = $tpc.GetService([type]"Microsoft.TeamFoundation.Build.Client.IBuildServer")

        if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition])
        {
            $buildDef = $BuildDefinition
        }
        else
        {
            $buildDef = $buildServer.GetBuildDefinition($tp.Name, $BuildDefinition);
        }

        $req = $buildDef.CreateBuildRequest()
        $req.GetOption = [Microsoft.TeamFoundation.Build.Client.GetOption] $GetOption;

        if ($GetOption -eq "Custom")
        {
            $req.CustomGetVersion = $GetVersion
        }

        if ($DropLocation)
        {
            $req.DropLocation = $DropLocation
        }

        $buildServer.QueueBuild($req)
    }
}