用于清除消息队列的 PowerShell 脚本不起作用

用于清除消息队列的 PowerShell 脚本不起作用

我从 PowerShell 库下载了一个脚本,该脚本应该用于清除 RabbitMQ 中的消息队列。但是,我遇到了一些无法修复的错误。所以我的脚本如下:

function Clear-RabbitMQQueue
{
[CmdletBinding(SupportsShouldProcess=$false, ConfirmImpact="High")]
Param
(
    # Name of RabbitMQ Virtual Host.
    [parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true, Position=0)]
    [Alias("test_test", "vhost")]
    [string]$VirtualHost = $defaultVirtualHost,

    # The name of the queue from which to receive messages
    [parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true, Position=1)]
    [Alias("test_Test", "QueueName")]
    [string]$Name,

    # Name of the computer hosting RabbitMQ server. Defalut value is localhost.
    [parameter(ValueFromPipelineByPropertyName=$true, Position=2)]
    [Alias("test_servername", "HostName")]
    [string]$BaseUri,

    # Credentials to use when logging to RabbitMQ server.
    [Parameter(Mandatory=$false)]
    [PSCredential]$Credentials
)

Begin
{
}
Process
{
    if ($pscmdlet.ShouldProcess("server: $BaseUri/$VirtualHost", "purge queue $Name"))
    {
        $url = Join-Path $BaseUri "/#/queues/$([System.Web.HttpUtility]::UrlEncode($VirtualHost))/$([System.Web.HttpUtility]::UrlEncode($Name))"
        Write-Verbose "Invoking REST API: $url"

        $result = Invoke-RestMethod $url -Credential $Credentials -AllowEscapedDotsAndSlashes -DisableKeepAlive -ErrorAction Continue -Method Delete
    }
}
End
{
}
}

Clear-RabbitMQQueue

我收到的错误是:

  Join-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
  At C:\Git Repository\Rabbit\Clear-RabbitMQQueue.ps1:33 char:30
  +             $url = Join-Path $BaseUri "/#/queues/$([System.Web.HttpUt ...
  +                              ~~~~~~~~
  + CategoryInfo          : InvalidData: (:) [Join-Path], 
  ParameterBindingValidationException
  + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand

Invoke-RestMethod : Cannot validate argument on parameter 'Uri'. The argument 
is null or empty. Provide an argument that is not 
null or empty, and then try the command again.
At C:\Git Repository\Rabbit\Clear-RabbitMQQueue.ps1:36 char:41
+             $result = Invoke-RestMethod $url -Credential $Credentials ...
+                                         ~~~~
+ CategoryInfo          : InvalidData: (:) [Invoke-RestMethod], 
ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

有人能帮我修复这些错误吗?很紧急!

更新

新代码:

Function Clear-RabbitMQQueue()
{

-virtualHost CCS_Loans2Go_DEV -Name computershare.infiniti.integration.test.Computershare.Infiniti.FormProcessing.Contracts:IFormSubmittedEvent.FormPrimedEvent.event -HostName rabbitmq-dev.emea.cshare.net

}

Clear-RabbitMQQueue

我收到的错误是:

-virtualHost : The term '-virtualHost' is not recognized as the name of a 
cmdlet, function, script file, or operable program. Check 
the spelling of the name, or if a path was included, verify that the path is 
correct and try again.
At line:4 char:5
+     -virtualHost CCS_Loans2Go_DEV -Name computershare.infiniti.integr ...
+     ~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (-virtualHost:String) [], 
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

相关内容