Clear-HTqueue.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function Clear-HTqueue {
    [CmdletBinding()]
    param (
        # Parameter help description
        [Parameter(Mandatory=$true)]
        [string]$QueueNamePattern
        
    )
    
    process {
        if($QueueNamePattern -eq '')
        {
            Write-Host "Queue name pattern is empty, nothing to clear.."
            return
        }
        $queuesToClear = Get-MsmqQueue | Where-Object { $_.QueueName -like  $QueueNamePattern }
        $queuesToClear | ForEach-Object {Write-Host "Clearing queue $($_.QueueName)" ; $_ | Clear-MsmqQueue | Out-Null}
    }
    
}