Public/Providers.ps1
function New-TMProvider { [CmdletBinding(DefaultParameterSetName = 'ByName')] param( [Parameter(Mandatory = $false)] [psobject] $TMSession = 'Default', [Parameter( Mandatory = $true, ParameterSetName = 'ByName', Position = 0)] [string] $Name, [Parameter(Mandatory = $true, ParameterSetName = 'ByObject', Position = 0)] [psobject] $Provider, [Parameter(Mandatory = $false)] [switch] $PassThru ) $TMSession = Get-TMSession $TMSession if ($PSCmdlet.ParameterSetName -eq 'ByName') { $Provider = New-Object -TypeName pscustomobject -Property @{ name = $Name } } $ProviderCheck = Get-TMProvider -Name $Provider.name if ($ProviderCheck) { Write-Verbose 'The provider already exists' return $PassThru.IsPresent ? $ProviderCheck : $null } $bodyParams = @{ name = $Provider.name description = $Provider.description comment = $Provider.comment project = $TMSession.UserContext.Project.Id } $Response = Invoke-TMRestMethod -api provider -Method Post -BodyParams $bodyParams if ($PassThru.IsPresent) { return $Response } } function Get-TMProvider { param( [Parameter(Mandatory = $false)][PSObject]$TMSession = 'Default', [Parameter(Mandatory = $false)][String]$Name, [Parameter(Mandatory = $false)][Switch]$ResetIDs ) $TMSession = Get-TMSession $TMSession $Response = Invoke-TMRestMethod -Api provider -Method Get $Response = $Response | Sort-Object -Property 'name' if ($ResetIDs) { foreach ($Result in $Response) { $Result.id = $null } } if ($Name) { return ($Response | Where-Object { $_.name -eq $Name }) } else { return $Response } } |