通过 Powershell DSC 下载文件时,无法为 SSL/TLS 安全通道建立信任关系



我正在尝试通过调用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:TempBuildPackageMyAPI.zip"))
        }
        SetScript = {
               $outfile = "C:TempBuildPackageMyAPI.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:TempBuildPackageMyAPI.zip"
            }           
    }

顺便说一句,我在使用[xRemoteFile]时也会遇到同样的错误。

尝试在Invoke-WebRequest之前添加它

[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"

最新更新