Powershell 3.0 Invoke-WebRequest HTTPS Fehlschlägt, auf Alle Anfragen

Ich versuche zu arbeiten mit unseren Load Balancer per Powershell 3.0 und ein REST-API. Allerdings bin ich derzeit immer ein Fehler, egal was ich versuche, wenn es sich um eine https-Anfrage, ob unsere load-balancer oder jede andere https-Seite. Ich fühle mich wie ich bin etwas fehlt offensichtlich.

Hier ist der code, der schlägt mit https

try
{
    #fails
    #$location='https://www.bing.com'
    #fails
    #$location='https://www.google.com'
    #fails
    #$location='https://www.facebook.com'
    #fails
    #$location='https://www.ebay.com'
    #works
    #$location='http://www.bing.com'
    #works
    #$location='http://www.google.com'
    #fails (looks like Facebook does a redirect to https://)
    $location='http://www.facebook.com'
    #works
    #$location='http://www.ebay.com'
    $response=''
    $response = Invoke-WebRequest -URI $location
    $response.StatusCode
    $response.Headers
}
catch
{
    Write-Host StatusCode $response.StatusCode
    Write-Host $_.Exception
}

Den Fehler den ich bekomme, ist:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.Management.Automation.PSInvalidOperationException: 
There is no Runspace available to run scripts in this thread. You can provide one in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspa
ce type. The script block you attempted to invoke was: $true
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()

Ich hatte gehofft, auf dieser Seite und die Vorschläge, die in Richtung des Bodens, einschließlich der von Aaron D.) würde einen Unterschied machen, aber keiner von Ihnen machte einen Unterschied.

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

und

function Ignore-SSLCertificates
{
    $Provider = New-Object Microsoft.CSharp.CSharpCodeProvider
    $Compiler = $Provider.CreateCompiler()
    $Params = New-Object System.CodeDom.Compiler.CompilerParameters
    $Params.GenerateExecutable = $false
    $Params.GenerateInMemory = $true
    $Params.IncludeDebugInformation = $false
    $Params.ReferencedAssemblies.Add("System.DLL") > $null
    $TASource=@'
    namespace Local.ToolkitExtensions.Net.CertificatePolicy
    {
        public class TrustAll : System.Net.ICertificatePolicy
        {
            public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem)
            {
                return true;
            }
        }
    }
'@ 
    $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
    $TAAssembly=$TAResults.CompiledAssembly
    ## We create an instance of TrustAll and attach it to the ServicePointManager
    $TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
    [System.Net.ServicePointManager]::CertificatePolicy = $TrustAll
}

und

add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

Ich habe versucht, das Umschalten auf " Invoke-RestCommand aber ohne Erfolg, da bekomme ich die gleiche Antwort.

Fühlt es sich wie dieses etwas die Umwelt, weil ich kann nicht glauben, dass die oben nicht funktioniert für jemand anderes, aber ich habe versucht es auf einer workstation und auf einem server mit dem gleichen Ergebnis (nicht auszuschließen Umgebung komplett, aber ich weiß, dass Sie anders eingestellt).

Irgendwelche Gedanken?

  • OK, also es scheint durchaus etwas zu sein, was die Konfiguration bezogen. Diese Invoke-RestMethod -Uri "https://gdata.youtube.com/feeds/api/videos?v=2&q=PowerShell" funktioniert auf Windows Server 2012 mit PSVersion 3 0 -1 -1 funktioniert nicht auf Windows Server 2008 R2 mit einer PS-Version 3 0 -1 -1 Und funktioniert auch nicht unter Windows 8.1 mit einer version von 4 0 -1 -1
InformationsquelleAutor mapeterson42 | 2014-08-05
Schreibe einen Kommentar