0

我在将 Powershell 脚本从 PS5 转换为 PS7 时遇到了一些问题。

我的目标是获取有关远程服务器证书的信息。

这个 IP 可以是任何有证书的东西:

    $url = "https://192.168.1.1"
    [Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
    $req = [Net.HttpWebRequest]::Create($url)
    $req.GetResponse() 
    [datetime]$expiration = 
    [System.DateTime]::Parse($req.ServicePoint.Certificate.GetExpirationDateString())
    Write-Output $expiration

在 Powershell 5 中运行时,此脚本成功完成,输出如下:

IsMutuallyAuthenticated : False
Cookies                 : {}
Headers                 : {Accept-Ranges, Content-Length, Content-Type, Date...}
SupportsHeaders         : True
ContentLength           : 98540
ContentEncoding         : 
ContentType             : text/html
CharacterSet            : ISO-8859-1
Server                  : Microsoft-IIS/10.0

...

Date        : 7/7/2020 12:00:00 AM
...

此脚本$req.GetResponse在 Powershell 7 中运行时出错。

MethodInvocationException: Exception calling "GetResponse" with "0" argument(s): "The SSL connection could not be established, see inner exception. 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.Runspace type. The script block you attempted to invoke was:  $true "

有任何想法吗?

4

0 回答 0