@@ -36,34 +36,28 @@ function Test-AzDoServiceConnection {
3636 [string ]
3737 $CollectionUri ,
3838
39- # PAT to get access to Azure DevOps.
40- [Parameter ()]
41- [string ]
42- $PAT ,
43-
4439 # Collection Uri. e.g. https://dev.azure.com/contoso.
4540 [Parameter (Mandatory , ValueFromPipelineByPropertyName , ValueFromPipeline )]
4641 [string ]
4742 $ServiceConnectionName
4843 )
4944
5045 begin {
51- Write-Verbose " Starting function: Test-AzDoServiceConnection "
52- $getAzDoProjectSplat = @ {
53- CollectionUri = $CollectionUri
54- }
55- $ProjectId = ( Get-AzDoProject @getAzDoProjectSplat | Where-Object ProjectName -EQ $ProjectName ).Projectid
46+ $result = @ ()
47+ Write-Verbose " Starting function: Get-AzDoServiceConnection "
48+ }
49+
50+ process {
5651
5752 $getAzDoServiceConnectionSplat = @ {
58- CollectionUri = $CollectionUri
59- ProjectName = $ProjectName
53+ CollectionUri = $CollectionUri
54+ ProjectName = $ProjectName
55+ ServiceConnectionName = $ServiceConnectionName
6056 }
6157
6258 $Connections = Get-AzDoServiceConnection @getAzDoServiceConnectionSplat
63- }
6459
65- process {
66- $connectioninfo = $connections | Where-Object ServiceConnectionName -EQ $ServiceConnectionName
60+ $connectioninfo = Get-AzDoServiceConnection @getAzDoServiceConnectionSplat
6761
6862 $body = @ {
6963 dataSourceDetails = @ {
@@ -73,14 +67,15 @@ function Test-AzDoServiceConnection {
7367 }
7468
7569 $params = @ {
76- uri = " $CollectionUri /$ProjectId /_apis/serviceendpoint/endpointproxy?endpointId=$ ( $connectioninfo.ServiceConnectionId ) &api-version=7.2-preview.1"
70+ uri = " $CollectionUri /$ProjectName /_apis/serviceendpoint/endpointproxy?endpointId=$ ( $connectioninfo.ServiceConnectionId ) &api-version=7.2-preview.1"
7771 Method = ' POST'
72+ Headers = $script :header
7873 body = $Body | ConvertTo-Json - Depth 99
7974 ContentType = ' application/json'
8075 }
8176
8277 if ($PSCmdlet.ShouldProcess ($ProjectName , " Test service connection on: $ ( $PSStyle.Bold ) $ProjectName $ ( $PSStyle.Reset ) " )) {
83- $response = Invoke-RestMethod @Params
78+ $result = Invoke-RestMethod @Params
8479 if ($response.statusCode -eq ' badRequest' ) {
8580 Write-Error " Connection $ ( $connectioninfo.ServiceConnectionName ) is not working: error $ ( $response.errorMessage ) "
8681 } else {
0 commit comments