我想在新机器上安装RabbitMQ之后创建一个设置用户“George”的powershell脚本。使用Powershell通过API在RabbitMQ中创建用户
我不明白为什么这个脚本不起作用。
的最后一步给了我一个404 { “错误”: “找不到对象”, “原因”: “\” 找不到\ “\ n”}
$secpasswd = ConvertTo-SecureString 'guest' -AsPlainText -Force
$credGuest = New-Object System.Management.Automation.PSCredential ('guest', $secpasswd)
$secpasswd2 = ConvertTo-SecureString 'george' -AsPlainText -Force
$credAdmin2 = New-Object System.Management.Automation.PSCredential ('george', $secpasswd2)
$body = @{
'password' = 'george'
'tags' = 'administrator'
} | ConvertTo-Json
$vhosts1 = ''
$vhosts1 = Invoke-RestMethod 'http://localhost:15672/api/users/george' -credential $credGuest -Method Put -ContentType "application/json" -Body $body
write '1:' $vhosts1
$vhosts2 = Invoke-RestMethod 'http://localhost:15672/api/permissions/%2f/' -Method get -credential $credAdmin2
write '2:' $vhosts2
$body2 = @{
'username' = 'george'
'vhost' = '/'
'configure' = '.*'
'write' = '.*'
'read' = '.*'
} | ConvertTo-Json
write '3:' $body2
$vhosts3 = Invoke-RestMethod 'http://localhost:15672/api/permissions/%2f/george' -credential $credGuest -Method Put -ContentType "application/json" -Body $body2
write '4:' $vhosts3
我也试过格式化最后一步是这样的:
http://localhost:15672/api/permissions/george
相同的404错误。
我尝试了大约20,000种不同的发送命令的方式。从完全匹配其他例子到尝试一些抽象艺术和巫术魔法。在观看RabbitMQ的管理工具时,我可以看到George已经创建。他有一个空虚的鬼魂。所以前3个步骤完美地工作。
我想我刚刚发现了与RabbitMQ的Windows 2012 x64的另一个bug。 非常感谢您验证我的脚本确实可行。 当我在Windows 2012服务器上尝试脚本时,它以同样的404方式出错。 我毫不怀疑这是另一个RabbitMQ + Windows 2012问题,而不是别的。 – Lup 2015-04-02 18:10:33
也许是这样......但有一种观点拖延,你可以使这项工作! – FoxDeploy 2015-04-02 18:11:16
而RabbitMQ是一个了不起的工具。真的爱死它。 即使我发现的技术是hte答案,我仍然保持你的'答案'。 Cuase我现在正在使用你的代码......哈哈 – Lup 2015-04-02 18:36:27