我正在尝试使用 powershell 从 ibm 硬件管理控制台 (HMC) rest api 获取数据,但我似乎无法弄清楚
使用 curl 我可以使用示例 here 获取信息没问题,它需要分 3 个步骤完成
curl -k -c "cookies.txt" -i -X PUT -H "Content-Type: application/vnd.ibm.powervm.web+xml; type=LogonRequest" -H "Accept: application/vnd.ibm.powervm.web+xml; type=LogonResponse" -H "X-Audit-Memento: hmc_test" -d "@login.xml" https://<hmc server>:12443/rest/api/web/Logon
curl -k -c "cookies.txt" -b "cookies.txt" -H "Accept: application/atom+xml; charset=UTF-8" https://<hmc server>:12443/rest/api/uom/LogicalPartition -o "outfile.xml"
login.xml 文件包含以下内容
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LogonRequest xmlns="http://www.ibm.com/xmlns/systems/power/firmware/web/mc/2012_10/" schemaVersion="V1_0">
<UserID>user</UserID>
<Password>password</Password>
</LogonRequest>
我似乎无法将其转换为 Powershell Invoke-RestMethod 尝试进行身份验证,因此我什至还没有处理第二个命令
我得到的最接近的是给我一个 406 错误
这是我目前得到的
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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Now run the same command as PowerShell 6, minus the -SkipCertificateCheck flag
$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("user:password")); "Accept"="application/xml; type=LogonResponse";"data"="login.xml"}
#$Body = @{"data"="login.xml"}
Invoke-RestMethod - -Method POST -Header $Header -ContentType "" -uri "https://<hmc server>:12443/rest/api/web/Logon"
和输出:
Invoke-RestMethod : Console Internal Error Console Internal Error Details: HTTP status code: 406The resource identified by this request is only capable of generating
responses with characteristics not acceptable according to the request "accept" headers.
不确定这是否是创建它的方法。我只是尽量模仿 curl 语句。
我还需要在 powershell 中创建 cookie 吗?
提前致谢