This repository was archived by the owner on Jun 13, 2024. It is now read-only.

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
function Resolve-Location
2-
{
1+
function Resolve-Location {
32
[CmdletBinding()]
43
[OutputType([string])]
54
Param
65
(
7-
[Parameter(Mandatory=$true)]
6+
[Parameter(Mandatory = $true)]
87
[string]
98
$Location,
109

11-
[Parameter(Mandatory=$true)]
10+
[Parameter(Mandatory = $true)]
1211
[string]
1312
$LocationParameterName,
1413

@@ -27,54 +26,49 @@ function Resolve-Location
2726
)
2827

2928
# Ping and resolve the specified location
30-
if(-not (Test-WebUri -uri $Location))
31-
{
32-
if(Microsoft.PowerShell.Management\Test-Path -LiteralPath $Location)
33-
{
29+
if (-not (Test-WebUri -uri $Location)) {
30+
if (Microsoft.PowerShell.Management\Test-Path -LiteralPath $Location) {
3431
return $Location
3532
}
36-
elseif($CallerPSCmdlet)
37-
{
33+
elseif ($CallerPSCmdlet) {
3834
$message = $LocalizedData.PathNotFound -f ($Location)
3935
ThrowError -ExceptionName "System.ArgumentException" `
40-
-ExceptionMessage $message `
41-
-ErrorId "PathNotFound" `
42-
-CallerPSCmdlet $CallerPSCmdlet `
43-
-ErrorCategory InvalidArgument `
44-
-ExceptionObject $Location
36+
-ExceptionMessage $message `
37+
-ErrorId "PathNotFound" `
38+
-CallerPSCmdlet $CallerPSCmdlet `
39+
-ErrorCategory InvalidArgument `
40+
-ExceptionObject $Location
4541
}
4642
}
47-
else
48-
{
43+
else {
4944
$pingResult = Ping-Endpoint -Endpoint $Location -Credential $Credential -Proxy $Proxy -ProxyCredential $ProxyCredential
5045
$statusCode = $null
5146
$exception = $null
5247
$resolvedLocation = $null
53-
if($pingResult -and $pingResult.ContainsKey($Script:ResponseUri))
54-
{
48+
if ($pingResult -and $pingResult.ContainsKey($Script:ResponseUri)) {
5549
$resolvedLocation = $pingResult[$Script:ResponseUri]
5650
}
5751

58-
if($pingResult -and $pingResult.ContainsKey($Script:StatusCode))
59-
{
52+
if ($pingResult -and $pingResult.ContainsKey($Script:StatusCode)) {
6053
$statusCode = $pingResult[$Script:StatusCode]
6154
}
6255

6356
Write-Debug -Message "Ping-Endpoint: location=$Location, statuscode=$statusCode, resolvedLocation=$resolvedLocation"
6457

65-
if((($statusCode -eq 200) -or ($statusCode -eq 401) -or ($statusCode -eq 407)) -and $resolvedLocation)
66-
{
67-
return $resolvedLocation
58+
if ((($statusCode -eq ([System.Net.HttpStatusCode]::OK) -or ($statusCode -eq [System.Net.HttpStatusCode]::Unauthorized) `
59+
-or ($statusCode -eq [System.Net.HttpStatusCode]::Forbidden) -or ($statusCode -eq [System.Net.HttpStatusCode]::MethodNotAllowed) `
60+
-or ($statusCode -eq [System.Net.HttpStatusCode]::ProxyAuthenticationRequired)) `
61+
-and $resolvedLocation) {
62+
return $resolvedLocation
6863
}
69-
elseif($CallerPSCmdlet)
70-
{
64+
elseif ($CallerPSCmdlet) {
7165
$message = $LocalizedData.InvalidWebUri -f ($Location, $LocationParameterName)
7266
ThrowError -ExceptionName "System.ArgumentException" `
73-
-ExceptionMessage $message `
74-
-ErrorId "InvalidWebUri" `
75-
-CallerPSCmdlet $CallerPSCmdlet `
76-
-ErrorCategory InvalidArgument `
77-
-ExceptionObject $Location
67+
-ExceptionMessage $message `
68+
-ErrorId "InvalidWebUri" `
69+
-CallerPSCmdlet $CallerPSCmdlet `
70+
-ErrorCategory InvalidArgument `
71+
-ExceptionObject $Location
7872
}
7973
}
8074
}

0 commit comments

Comments
 (0)