我尝试使用包含" @"的密码进行API调用。字符和我获得无效的凭据。
$Password = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Creds = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $Username, $Password
Invoke-RestMethod -Uri ("http://contoso") -Credential $Creds
答案 0 :(得分:1)
您必须转义特殊字符或将密码放在单引号中。
但正如@Lieven Keersmaekers所说 - @不是特别的字符。 因此,您必须查看是否还有其他问题:)
示例:
$Password = '$up@r' // -- This works (single quotes wont interpret the "special chars")
$Password = "`$up@r" // -- This works because you escaped the characters
$Password = "$up@r" // -- This wont work
更多例子:
PS > $Password = "H@ppy"
$Password
H@ppy
PS > $Password = '$uper H@ppy'
$Password
$uper H@ppy
PS > $Password = "`$uper H@ppy"
$Password
$uper H@ppy
看看这个Site
Greetz Eldo.Ob
答案 1 :(得分:0)
不是@导致问题,实际上是导致问题的密码$。
我在密码中添加了单引号,但它确实有效。
感谢您的建议。