|
1 |
| -function Resolve-Location |
2 |
| -{ |
| 1 | +function Resolve-Location { |
3 | 2 | [CmdletBinding()]
|
4 | 3 | [OutputType([string])]
|
5 | 4 | Param
|
6 | 5 | (
|
7 |
| -[Parameter(Mandatory=$true)] |
| 6 | +[Parameter(Mandatory = $true)] |
8 | 7 | [string]
|
9 | 8 | $Location,
|
10 | 9 |
|
11 |
| -[Parameter(Mandatory=$true)] |
| 10 | +[Parameter(Mandatory = $true)] |
12 | 11 | [string]
|
13 | 12 | $LocationParameterName,
|
14 | 13 |
|
@@ -27,54 +26,49 @@ function Resolve-Location
|
27 | 26 | )
|
28 | 27 |
|
29 | 28 | # 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) { |
34 | 31 | return $Location
|
35 | 32 | }
|
36 |
| -elseif($CallerPSCmdlet) |
37 |
| -{ |
| 33 | +elseif ($CallerPSCmdlet) { |
38 | 34 | $message = $LocalizedData.PathNotFound -f ($Location)
|
39 | 35 | 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 |
45 | 41 | }
|
46 | 42 | }
|
47 |
| -else |
48 |
| -{ |
| 43 | +else { |
49 | 44 | $pingResult = Ping-Endpoint -Endpoint $Location -Credential $Credential -Proxy $Proxy -ProxyCredential $ProxyCredential
|
50 | 45 | $statusCode = $null
|
51 | 46 | $exception = $null
|
52 | 47 | $resolvedLocation = $null
|
53 |
| -if($pingResult -and $pingResult.ContainsKey($Script:ResponseUri)) |
54 |
| -{ |
| 48 | +if ($pingResult -and $pingResult.ContainsKey($Script:ResponseUri)) { |
55 | 49 | $resolvedLocation = $pingResult[$Script:ResponseUri]
|
56 | 50 | }
|
57 | 51 |
|
58 |
| -if($pingResult -and $pingResult.ContainsKey($Script:StatusCode)) |
59 |
| -{ |
| 52 | +if ($pingResult -and $pingResult.ContainsKey($Script:StatusCode)) { |
60 | 53 | $statusCode = $pingResult[$Script:StatusCode]
|
61 | 54 | }
|
62 | 55 |
|
63 | 56 | Write-Debug -Message "Ping-Endpoint: location=$Location, statuscode=$statusCode, resolvedLocation=$resolvedLocation"
|
64 | 57 |
|
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 |
68 | 63 | }
|
69 |
| -elseif($CallerPSCmdlet) |
70 |
| -{ |
| 64 | +elseif ($CallerPSCmdlet) { |
71 | 65 | $message = $LocalizedData.InvalidWebUri -f ($Location, $LocationParameterName)
|
72 | 66 | 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 |
78 | 72 | }
|
79 | 73 | }
|
80 | 74 | }
|
0 commit comments