Helpers/Helpers.ps1
Function Get-TfsRestClient { [CmdletBinding()] [OutputType('Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase')] Param ( [Parameter(Mandatory=$true, Position=0)] [string] $Type, [Parameter()] [object] $Collection ) Process { return _GetRestClient @PSBoundParameters } } <# .SYNOPSIS Short description .DESCRIPTION Long description .EXAMPLE PS C:> <example usage> Explanation of what the example does .INPUTS Inputs (if any) .OUTPUTS Output (if any) .NOTES General notes #> Function Invoke-TfsRestApi { [CmdletBinding()] Param ( [Parameter(Position=0, Mandatory=$true, ParameterSetName="Library call")] [Alias("Name")] [Alias("API")] [string] $Operation, [Parameter(ParameterSetName="Library call")] [Alias("Client")] [Alias("Type")] [string] $ClientType, [Parameter(ParameterSetName="Library call")] [object[]] $ArgumentList, [Parameter(ParameterSetName="Library call")] [string] $ErrorMessage, [Parameter(ParameterSetName="Library call")] [object] $Collection, [Parameter()] [switch] $AsTask ) End { $tpc = Get-TfsTeamProjectCollection -Collection $Collection; if (-not $tpc -or ($tpc.Count -ne 1)) {throw "Invalid or non-existent team project collection $Collection."} $client = _GetRestClient $ClientType -Collection $tpc $task = $client.$Operation.Invoke($ArgumentList) if ($AsTask) { return $task } $result = $task.Result; if($task.IsFaulted) { _throw $Message $task.Exception.InnerExceptions } return $result } } |