【发布时间】:2022-01-06 08:26:58
【问题描述】:
我尝试使用来自https://www.powershellgallery.com/packages/HPERedfishCmdlets/1.1.0.0 的 HPECMDLets。
当我连接到 HPE 服务器时,我收到以下错误:
Line |
72 | [System.Net.WebResponse] $resp = $httpWebRequest.GetResponse()
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "GetResponse" with "0" argument(s): "The SSL connection could not be established, see inner exception."
InnerException ($Errors[0].Exception.InnerException | FL *) 是:
InvalidOperation: Cannot index into a null array.
我正在使用带有 PowerShell 7.2 的 Windows Server 2012R2。
我还尝试弄清楚 Connect-HPERedfish 函数的结构并创建自己的脚本:
$Credential = Import-Clixml -Path "<Path-to-Credential>"
$Address = '192.168.1.1'
$DisableCertificateAuthentication = $True
$DisableExpect100Continue = $True
$session = $null
$wr = $null
$httpWebRequest = $null
$OrigCertFlag = $false
$un = $Credential.UserName
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password)
$pw = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($bstr)
$unpw = @{'UserName'=$un; 'Password'=$pw}
$jsonStringData = $unpw | ConvertTo-Json
$session = $null
[IPAddress]$ipAddress = $null
if([IPAddress]::TryParse($Address, [ref]$ipAddress))
{
if(([IPAddress]$Address).AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetworkV6 -and $Address.IndexOf('[') -eq -1)
{
$Address = '['+$Address+']'
}
}
$baseUri = "https://$Address"
$odataid = "/redfish/v1/"
$uri = (New-Object System.Uri -ArgumentList @([URI]$baseUri, $Odataid)).ToString()
$method = "GET"
Start-Sleep -Milliseconds 300
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$wr = [System.Net.WebRequest]::Create($uri)
$httpWebRequest = [System.Net.HttpWebRequest]$wr
$httpWebRequest.Method = $method
$httpWebRequest.AutomaticDecompression = [System.Net.DecompressionMethods]::GZip
$httpWebRequest.Headers.Add('Odata-version','4.0')
$httpWebRequest.ServicePoint.Expect100Continue = -not($DisableExpect100Continue)
$httpWebRequest.ServerCertificateValidationCallback = {$DisableCertificateAuthentication}
[System.Net.WebResponse] $resp = $httpWebRequest.GetResponse() << Error!
到目的地的 Invoke-Webrequest 成功:
Invoke-WebRequest https://192.168.1.1/ -SkipCertificateCheck
另外 - 使用 PowerShell 5,使用上述脚本连接到服务器是成功的! 那么,为什么我在使用 PowerShell 7 时遇到错误?
非常感谢您的帮助
PS:有时复制粘贴错误可能是致命的: 内部异常现在给了我正确的输出:
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.Runspace type.
The script block you attempted to invoke was: $false
我找到了关注的帖子:https://github.com/PowerShell/PowerShell/issues/11658,但那里指向所谓的解决方案的链接不起作用..
PPS:关于https://www.agilepointnxblog.com/powershell-error-there-is-no-runspace-available-to-run-scripts-in-this-thread我删除了ServerCertificateValidationCallback属性:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = $null
但这会导致innerException:
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch, RemoteCertificateChainErrors
所以我需要将 [System.Net.ServicePointManager]::ServerCertificateValidationCallback 设置为 $true 以跳过证书检查..
【问题讨论】:
标签: https windows2012 powershell-7.2