I have a script like this:
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}
}
Everything fine, when I launch it from PowerShell ISE, but when I run it from PowerShell I get an error:
The remote server returned an error: (405) Method Not Allowed.
I know, that it can be somehow connected with RabbitMq, but I don't see how, because it is just a simple request.
Can you help me find a root cause of these differences?