I'm trying to download a file via by invoking a web request inside a Powershell DSC.
When i execute the script i get the error
PowerShell DSC resource MSFT_ScriptResource failed to execute Set-
TargetResource functionality
with error message: The underlying connection was closed: Could not
establish trust relationship for the SSL/TLS secure channel.
If i invoke the web request with the same headers and proxy outside of DSC, the request succeeds. What can i do to make the request work inside DSC?
Script DownloadArtifact{
GetScript =
{
Result = ('True' -in (Test-Path -Path "C:\Temp\BuildPackage\MyAPI.zip"))
}
SetScript = {
$outfile = "C:\Temp\BuildPackage\MyAPI.zip"
$headers = @{"Authorization"="Basic <redacted>"}
$uri = "https://mycompany.visualstudio.com/_apis/build/builds/10374/artifacts/?artifactName=MyAPI&%24format=zip"
Invoke-WebRequest -Uri $uri -OutFile $outfile -Headers $headers -Proxy "http://proxy:8080"
Unblock-File -Path $outfile;
}
TestScript =
{
Test-Path -Path "C:\Temp\BuildPackage\MyAPI.zip"
}
}
Incidentally i get the same error when using [xRemoteFile]
too.