![](/img/trans.png)
[英]Powershell Code is working well on Powershell.exe and Powershell ISE but not working on VS Code
[英]Different behavior between PowerShell vs PowerShell ISE
我有一個像這樣的腳本:
Write-Host "Create RabbitMQ infrastructure..."
$rabbitHost = "http://my.company.com:15672"
$serverPort = 12345
$prefix = "unit"
$user = "test"
$pass = "test"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
$exchanges = ("MyExchange")
$exchanges | foreach {
Write-Host "Create $_"
$body = @{
type = "direct"
durable = "true"
}
$json = $body | ConvertTo-Json
try{
$url = "$rabbitHost/api/exchanges/%2f/$prefix" + "_" + "$serverPort" + "_" + $_
Invoke-RestMethod $url -Body $json -Method Put -Credential $cred -ContentType 'application/json'
} catch {$_.Exception}
}
從PowerShell ISE啟動它時一切正常,但是從PowerShell運行它時出現錯誤:
遠程服務器返回錯誤:(405)不允許使用方法。
我知道,它可以某種方式與RabbitMq連接,但我不知道如何,因為它只是一個簡單的請求。
您能幫我找到這些差異的根本原因嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.