我正在尝试通过在 Powershell DSC 中调用 Web 请求来下载文件。
当我执行脚本时,我得到了错误
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.
如果我在 DSC 之外使用相同的标头和代理调用 Web 请求,则请求成功。我该怎么做才能使请求在 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"
}
}
顺便说一句,我在使用时也遇到了同样的错误[xRemoteFile]
。