这是我的代码:
$appliance = Read-Host "OneView Address"
$userName = Read-Host "Username"
$password = Read-Host "Password" -AsSecureString
$url = "https://$appliance"
$user = @{
userName= "$($userName)"
password= "$($password)"
authnHost= "$appliance"
authLoginDomain= "Local"
}
$json = $user | ConvertTo-Json
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-type", 'application/json')
$headers.Add("Accept", 'application/json')
$uri = $url + '/rest/login-sessions'
$response = Invoke-RestMethod -Uri $uri -Method POST -Headers $headers -Body $json -ContentType 'application/json'
当我运行它时,我收到以下错误:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\myscript.ps1:54 char:13
+ $response = Invoke-RestMethod -Uri $uri -Method POST -Headers $header ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
当我不使用参数“-AsSecureString”读取密码时,它可以工作。
有人可以告诉我这里有什么问题吗?
提前致谢。