diff --git a/cluster/gce/windows/common.psm1 b/cluster/gce/windows/common.psm1 index d057f24e54e..4a292077e86 100644 --- a/cluster/gce/windows/common.psm1 +++ b/cluster/gce/windows/common.psm1 @@ -202,6 +202,11 @@ function Get-RemoteFile { [parameter(Mandatory = $false)] [System.Collections.IDictionary]$Headers = @{} ) + # Load the System.Net.Http assembly if it's not loaded yet. + if ("System.Net.Http.HttpClient" -as [type]) {} else { + Add-Type -AssemblyName System.Net.Http + } + $timeout = New-TimeSpan -Minutes 5 try { @@ -215,19 +220,19 @@ function Get-RemoteFile { # If the URL is for GCS and the node has dev storage scope, add the # service account OAuth2 bearer token to the request headers. # https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#applications - if (($Url -match "^https://storage`.googleapis`.com.*") -And $(Check-StorageScope)) { + if (($Url -match "^https://storage`.googleapis`.com.*") -and $(Check-StorageScope)) { $httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer $(Get-Credentials)") } # Attempt to download the file $httpResponseMessage = $httpClient.GetAsync([System.Uri]::new($Url)) $httpResponseMessage.Wait() - if (-Not $httpResponseMessage.IsCanceled) { + if (-not $httpResponseMessage.IsCanceled) { # Check if the request was successful. # # DO NOT replace with EnsureSuccessStatusCode(), it prints the # OAuth2 bearer token. - if (-Not $httpResponseMessage.Result.IsSuccessStatusCode) { + if (-not $httpResponseMessage.Result.IsSuccessStatusCode) { $statusCode = $httpResponseMessage.Result.StatusCode throw "Downloading ${Url} returned status code ${statusCode}, retrying." }