我正在尝试整理一个脚本来监控服务器上的MSMQ。我找到了this,它就像一个魅力,但我也需要到达时间。
使用Get-Member cmdlet时,我会获得一个属性列表,但似乎没有任何东西可以让我得到我需要的东西。
有谁知道如何到达时间?
/ G
答案 0 :(得分:2)
$qname = "<YourQueueNameHere>"
[Reflection.Assembly]::LoadWithPartialName("System.Messaging") | out-null
$q = new-object System.Messaging.MessageQueue($qname)
$msgs = $q.GetAllMessages()
foreach ( $msg in $msgs )
{
Write-Host $msg.ArrivedTime
}
答案 1 :(得分:2)
终于明白了。
[String]$cName = $Env:COMPUTERNAME
[Reflection.Assembly]::LoadWithPartialName("System.Messaging") | out-null
[System.Messaging.MessageQueue[]]$queues = [System.Messaging.MessageQueue]::GetPrivateQueuesByMachine($cName.ToLower())
Foreach ($queue in $queues) {
$queue.MessageReadPropertyFilter.SetAll()
try {
[System.Messaging.Message]$message = $queue.Peek(10)
Write-Host $queue.QueueName $message.ArrivedTime
}
catch {
#Write-Host "Timeout"
}
}
诀窍是设置MessageReadPropertyFilter。可以单独设置每个属性,但现在这样做。
答案 2 :(得分:1)
这对我有用。就我而言,该脚本计算过去一个小时内收到的邮件数量。
$QueueArray = "MyQueue1.ERRORS", "MyQueue2.ERRORS";
foreach ($queue in $QueueArray)
{
# Create each MSMQ object
[System.Reflection.Assembly]::LoadWithPartialName("System.Messaging") | Out-Null
$MessageQueue = New-Object System.Messaging.MessageQueue (".\private$\" + $queue)
# Get the amount of the messages in the queue for the past hour.
$MessageQueue.MessageReadPropertyFilter.SetAll()
$PastHour = (Get-Date).AddHours(-1)
$countFailedMessages = 0
foreach ($message in $MessageQueue )
{
if ($PastHour -lt $message.ArrivedTime)
{
#Write-Host $message.ArrivedTime
$countFailedMessages++
#Write-Host $countFailedMessages
}
}
Write-Host $queue `t $countFailedMessages "failed messages for the past hour"
}