Peeking at messages in MSMQ with PowerShell...

Hello,
I am a n00b to PowerShell and I am trying to create some maintenance script to manage our MSMQs ... so go easy on me! :P  I am currently trying to create a filtered list of message IDs by providing a cutoff date.  The problem is when I try to grab
the ArriveTime or SentTime from the message it is always null-valued expression (and coughs up an exception).  Oh, yeah!  The messages I'm trying to sort through are in the journal.
I have written these functions based on various example (C# and PS) on the Net.  There could be some gross inefficiencies and a lot of overkill but I think you get the basic idea.
function PeekWithoutTimeout([System.Messaging.MessageQueue] $q, [System.Messaging.Cursor] $cursor, [System.Messaging.PeekAction] $action)
[System.Messaging.Message] $Return = $null
[TimeSpan] $ts = [TimeSpan] '00:00:01'
try
$Return = $q.Peek($ts, $cursor, $action)
catch [System.Messaging.MessageQueueException]
$ErrorMessage = $_.Exception.Message
if (!$ErrorMessage.ToLower().Contains("timeout"))
throw $ErrorMessage
return $Return
function GetFilteredMessageList([System.Messaging.MessageQueue] $q, [System.DateTime] $cutoff)
[System.Collections.ArrayList] $list = New-Object -TypeName System.Collections.ArrayList
[System.DateTime] $sentTime = New-Object -TypeName System.DateTime
[System.Messaging.Cursor] $cursor = $q.CreateCursor()
$peekActionCurrent = [System.Messaging.PeekAction]::Current
$peekActionNext = [System.Messaging.PeekAction]::Next
[System.Messaging.Message] $m = PeekWithoutTimeout $q $cursor $peekActionCurrent
if ($m -ne $null)
$sentTime = [System.DateTime]::Parse($m.SentTime.ToString()) #exception here
Write-Host $sentTime #debug statement
if($sentTime -le $cutoff)
$list.Add($m.Id.ToString())
while (($m = PeekWithoutTimeout $q $cursor $peekActionNext) -ne $null)
$sentTime = [System.DateTime]::Parse($m.SentTime.ToString())
if($sentTime -le $cutoff)
$list.Add($m.Id.ToString())
return $list.ToArray()
}$cutoff = [System.DateTime]::Parse("11/7/2013 11:58:30 AM")
GetFilteredMessageList ".\private$\main\Journal$" $cutoff
Is there a better way to do this?
TIA!

If you know MQ then you know ther are no efficiencies in peeking.  It is a utility function.
If it works be set.  The code seems normal.  I see no big issues.
C# examples are a good place to start but be adventurous, apply PowerShell to the task.  Processing messages is a good candidate for the pipeline.
MQ is easy.  It only becomes an issue when you add work flows to it.
¯\_(ツ)_/¯

Similar Messages

  • Using Microsoft Message Queues (MSMQ) with LabVIEW

    I want to use the Microsoft Message Queue to communicate between applications on different machines. Does anybody have experience in using the MSMQ with Labview (in the .NET framework)? How do I send messages? The MessageQueue.Send method requires an object, and I don't know how to create this object format.
    This question was asked several years ago on this forum and no answer was given.
    I would appreciate any examples of Create a Queue, Delete a Queue,  Send a Message, and Read a Message in LabVIEW 7 or earlier.
    Thanks,

    P.C.
    I'm a little confused by what you mean.  I thought you were sending messages through the MSMQ, but the code there would receive a message, get the body, then display the body of the message.  The Object that the invoke node refers to is the Body of the Message, which has no properties, but has a few methods like ToString that you can use to get the string from the Body. 
    You need to wire up the references into the invoke and property nodes to get the selection of the methods or properties that are available.  Do they just not appear when you are using the invoke node with a reference to the body?
    Message Edited by Coal Man on 06-04-2007 01:56 PM
    Brian Coalson
    Software Engineer
    National Instruments
    Attachments:
    msmq.Jpg ‏40 KB

  • Exchange 2010 - Report NDRs with powershell

    Hi all,
    I would like to analyze all internal NDRs within my exchange environment. For example we have systems which are hard coded with email addresses of internal recipients and people leave the business and their mailbox and associated email address will be removed
    from exchange but not from a third party system that has a list of addresses to send notifications out to or home grown scripts. In order to keep the email pipeline clean and follow best practices I would like to catch these NDRs and remove them from the relevant
    systems.
    Is there anyway I can do this with powershell, my environment Exchange 2010 SP2 and all the roles are on a single server.

    Hi Niko,
    I have just performed the following test:
    sent an email to an internal recipient were the address does not exist, example
    [email protected]
    The NDR does not come from [email protected]
    The headers for the NDR I got as listed below:
    MIME-Version: 1.0
    From: Microsoft Outlook
     <[email protected]>
    To: <[email protected]>
    Date: Thu, 11 Dec 2014 08:55:54 +0000
    Content-Type: multipart/report; report-type=delivery-status;
     boundary="129b7383-6632-4979-ab4a-e5742a33ae6b"
    X-MS-Exchange-Organization-SCL: -1
    Content-Language: en-GB
    Message-ID: <[email protected]>
    In-Reply-To: <[email protected]com>
    References: <[email protected]com>
    Thread-Topic: test
    Thread-Index: AdAVIEZfXlpAxeICRk2Dg71q+Amr/wAAADyf
    Subject: Undeliverable: test
    X-MS-Exchange-Organization-AuthSource: exchangeserver.mydomain.com
    X-MS-Exchange-Organization-AuthAs: Internal
    X-MS-Exchange-Organization-AuthMechanism: 05

  • How to create an azure website with PowerShell?

    Hello
    I'm, trying to create a new wordpress website in Azure with PowerShell, I saw a video: https://www.youtube.com/watch?v=LHjkn59Lf0g
    But, When execute my code, I get the following error:
    New-AzureResourceGroup :
    06:42:41 p. m. - Resource SuccessBricks.ClearDB/databases 'dbdb3' failed with message 'User
    failed validation to purchase resources. Error message: '["Credit Card is the only supported payment instrument for
    purchases"]''
    What Can I do?
    I have a bizspark subscription with enough money :S
    THANKS!

    Hi Victor,
    Thanks for your question.
    Firstly, I recommend you to create the website and recourse group in Azure portal to see if the issue persists.
    In addition, I will have a test for this and feedback to you later. Appreciate your patience.
    Best regards,
    Susie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Adding a CI Build with powershell

    Hi,
    Adding a CI Build (class: System.Build) with powershell to Service Manager 2012 R2 results in an error, but the Build is added with the correct properties. Here is the error message:
    New-SCSMObject : Item has already been added. Key in dictionary: 'Notes'  Key being added: 'Notes'
    At line:1 char:15
    + new-SCSMObject <<<<  (get-scsmclass System.Build) -propertyhashtable ($build)
        + CategoryInfo          : InvalidOperation: (Notes:ManagementPackProperty) [New-SCSMObject], ArgumentException
        + FullyQualifiedErrorId : property 'Notes' has already been added to collection,SMLets.NewSMObjectCommand
    here is what I do:
    $build=@{Displayname = "Test 1"}$build+=@{AssetStatus = "Deployed"}$build+=@{ObjectStatus = "Active"}$build+=@{Category = "Software"}$build+=@{Title = "Test"}$build+=@{Version = "1"}new-SCSMObject (get-scsmclass System.Build) -propertyhashtable ($build)
    If I querry this Object with
    get-scsmobject (get-scsmclass System.Build$) -Filter "Displayname -eq 'Test 1'"
    I get the warning:
    WARNING: The property 'Notes' already exists, skipping.
    Exception: The member "Notes" is already present.
    In my Build Form there are also two "notes" fields.
    So my questions:
    a) does this occur on other installations?
    b) If not: any idea, where this comes from or how I could find out.
    b) If yes: how do you deal with it?
    tia
    Patrick Wahlmüller

    Hi Roman,
    Thanks for your response.
    Here are some findings: Smlets are not exact enough, because in the System.build Object there are 2 Notes Fields. One from the System.ConfigItem class and one from the System.Build class. I do not understand the reason for two notes fields, but the smlets
    have a problem with it and the result is a warning. You can suppress this by
    get-scsmobject (get-scsmclass
    System.Build$)
    -Filter "Displayname -eq 'Test 1'" -WarningAction silentlycontinue
    (thanks to
    Jason)
    When I use native cmdlets:
    Get-SCSMClassInstance -class $buclass -Filter 'Displayname -eq "Test 1"'
    Results in two notes fields:
    Notes
    System.ConfigItem_Notes
    But, I'll give it a try with native cmdlets, since the are part of the product.
    But one question remains: Why are there two notes fields?
    Patrick Wahlmüller

  • Re-map print queues for clients with powershell

    We reinstalled printer queues (share printer name is the same as before) and drivers on server, 99% users can't print properly, is a way to re-map print queues for all clients with PowerShell equivalent to remove and map again?

    Hi Brent,
    To re-map all of the printers, please check this script written by Boe Prox:
    <#
    .SYNOPSIS
    Logon Script to migrate printer mapping
    .DESCRIPTION
    Logon Script to migrate printer mappings
    .NOTES
    Author: Boe Prox
    Create: 09 NOV 2012
    Modified:
    Version 1.0 - Initial Script Creation
    1.1 Added Header Text for CSV file
    #>
    Param (
    $newPrintServer = "Server2",
    $PrinterLog = "\\LogSVR\PrintMigration$\PrintMigration.csv"
    <#
    #Header for CSV log file:
    "COMPUTERNAME,USERNAME,PRINTERNAME,RETURNCODE-ERRORMESSAGE,DATETIME,STATUS" |
    Out-File -FilePath $PrinterLog -Encoding ASCII
    #>
    Try {
    Write-Verbose ("{0}: Checking for printers mapped to old print server" -f $Env:USERNAME)
    $printers = @(Get-WmiObject -Class Win32_Printer -Filter "SystemName='\\\\Server1'" -ErrorAction Stop)
    If ($printers.count -gt 0) {
    ForEach ($printer in $printers) {
    Write-Verbose ("{0}: Replacing with new print server name: {1}" -f $Printer.Name,$newPrintServer)
    $newPrinter = $printer.Name -replace "Server1",$newPrintServer
    $returnValue = ([wmiclass]"Win32_Printer").AddPrinterConnection($newPrinter).ReturnValue
    If ($returnValue -eq 0) {
    "{0},{1},{2},{3},{4},{5}" -f $Env:COMPUTERNAME,
    $env:USERNAME,
    $newPrinter,
    $returnValue,
    (Get-Date),
    "Added Printer" | Out-File -FilePath $PrinterLog -Append -Encoding ASCII
    Write-Verbose ("{0}: Removing" -f $printer.name)
    $printer.Delete()
    "{0},{1},{2},{3},{4},{5}" -f $Env:COMPUTERNAME,
    $env:USERNAME,
    $printer.Name,
    $returnValue,
    (Get-Date),
    "Removed Printer" | Out-File -FilePath $PrinterLog -Append -Encoding ASCII
    } Else {
    Write-Verbose ("{0} returned error code: {1}" -f $newPrinter,$returnValue) -Verbose
    "{0},{1},{2},{3},{4},{5}" -f $Env:COMPUTERNAME,
    $env:USERNAME,
    $newPrinter,
    $returnValue,
    (Get-Date),
    "Error Adding Printer" | Out-File -FilePath $PrinterLog -Append -Encoding ASCII
    } Catch {
    "{0},{1},{2},{3},{4},{5}" -f $Env:COMPUTERNAME,
    $env:USERNAME,
    "WMIERROR",
    $_.Exception.Message,
    (Get-Date),
    "Error Querying Printers" | Out-File -FilePath $PrinterLog -Append -Encoding ASCII
    Quote from:
    Use a PowerShell Logon Script To Update Printer Mappings
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • MSMQ with Labview

    I want to use the Microsoft Message Queue to communicate between applications on different machines. Does anybody have experience in using the MSMQ with Labview (in the .NET framework)? How do I send messages? The MessageQueue.Send method requires an object, and I don't know how to create this object format.

    Jim,
    please find attached an MSMQ send/receive example I've created with LabVIEW 8.2.1
    To get it working, you need to do the following:
    1. Make sure MSMQ is installed on all involved machines, senders and receivers. The attached ZIP archive contains batch files to install MSMQ on Windowx XP and Vista in the so-called workgroup mode (does not involve active directory integration).
    2. Manually create a private queue named "labQueue" or whatever you like on the receiving(!) MSMQ target machine.
    See http://technet2.microsoft.com/windowsserver/en/library/53f029d6-8824-4b1b-a312-167b03f5fca51033.mspx... for instructions to do so.
    Important note: people often misunterstand the term "private" in a way that such queues would only work locally, within one machine. This is not the case, in fact there is no kind of local-only receive queue like there is no local-only TCP port binding and private queues are open to get messages from anywhere. They are just not public to the active directory queue management services so any sender needs to know the correct target address itself.
    3. Adapt the "FormatName" string of the SampleSender.vi that it points to the queue on the MSMQ receiver, that is: Insert the queue name you've chosen and replace the IP with the address of the target machine.
    Run both VIs, SampleSender.vi and SampleReceiver.vi and send single messages typed into the "myMessage" string control by pressing the "Send" button or create looped bulk messages with the corresponding boolean switch control.
    To experience the coolness of MSMQ, send some messages from the running sender VI before the receiver was started, then start the receiver VI. Or run both VIs on 2 different machines, unplug the LAN connection of one while still sending messages and then plug it in again. MSMQ does all the caching for you in case one of the peers is temporarily unavailable. This rocks!
    The VIs demonstrate a very straight forward use of the .NET System.Messaging namespace for synchronous MSMQ messaging. A more elaborate (and better) way included the automatic creation of non-exisiting receive queues and asynchronous message receiving with .NET events.
    Greetings + have fun,
    Hans
    Attachments:
    MessageQueue (MSMQ).zip ‏31 KB

  • I can no longer log into my ichat linked to my gmail.  right after opening up ichat, receive the following message:  lost connection with jabber.  the server has unexpectedly disconnected.

    i can no longer log into my ichat linked to my gmail.  right after opening up ichat, receive the following message:  lost connection with jabber.  the server has unexpectedly disconnected.  how to troubleshoot?  thanks.

    Hi,
    There can be many reasons why the Login is "up the creek".
    Any break in the network at your end whilst logged in will cause  an issue.
    A sort of discrepancy between what iChat thinks the state should be and what the server thinks.
    If they don't agree the server will refuse to accept.
    A Crash at the server end which does not log you out properly will also do it.
    Any file at any time can be come corrupted.
    Luckily with the iChat .plists they are recreated if removed with an iChat Restart.
    If it were AIM you can also get your Account Suspended  and this will not log you in.
    (It tends to happen from Chat rooms where people notify AIM about bad behaviour (as they see it) and you have to apply to get Un-suspended).
    Most of the big IM services use multiple servers.
    Sometimes these go out of Sync.
    In the case of AIM this happens when they remove Old unused Screen Names from people's Buddy List prior to making them available for re-registration.  I am not sure if this happens at Google.
    You seem to be talking about an account that has worked at Work and having new computer at home.
    As I mentioned the Priority thing you have not said that it has coincided with the new computer logging in  (this will kick the work Computer out of Google whether you are logged in  on the Web Mail page or in iChat)
    IN addition to that iChat stays partially logged in for Off Line IMs
    This is done in the background by a support app called iChatAgent
    If your Computer is ON but ichat is not started people can still send you Messages.
    Instead of saving these on the server until you login iChat will start up.
    Depending if the home Mac is effecting the Work Login it may be holding sway over your Login.
    Using your girlfriend's login may have booted her Off Line where she normally uses the name/login.
    The AIM Side can be specifically set to allow Multiple Logins and therefore NOT allow them.  If this happens you get a warning and messages to do something about it.
    You do not get these in any Jabber or Google Login as the Priority setting is supposed to take care of it.
    If the Login works at the Web Mail Login and on one computer then the .plist on the work computer is the most likely issue.
    There is a small chance that a Corrupt Buddy Pic (Home Folder/Library/Caches/com.apple.iChat/Pictures) may be the cause.
    Set this folder to icon view and also use the Finder's View Menu > Show View Options and select icon view.
    This should show all pics as their icon.
    Check that all display properly.
    At this point I would try a COMBO version update install of the last Update you did over what you have.
    This often corrects hard to trace things
    The 10.5.8 COMBO is here
    11:28 PM      Monday; June 20, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.7)
     Mac OS X (10.6.7),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Internet Download error message: the connection with the server has been reset

    With an WRT54GS v6 firmware v 1.50.9 on Windows XP SP2 with Internet Explorer 7, Intel wireless internal adaptor w/ 802.11b,  I was getting the error message "The connection with the server has been reset" when downloading most anything from the Internet.  My IP address would then be reset and download would be interrupted.  To resolve, I turned off the WZC (Wireless Zero Configuration) Services, and this seems to correct the problem.
    Control Panel > Admin Tools > Services > Wireless Zero Configuration > Disable
    Hopes this helps.

    Hi!
    Im using Windows 7.... I tried looking for the Wireless Config - but it isn't in the Services options!
    So, what can I do now?
    Thanx

  • Problem with HP pavillion dv7 giving message (a problem with the internal fan enter = shutdown

    HP Pavillion DV7 notebook PC
    Windows 7 64
    intel I5
    6 gig memory
    service pack 1
    I am trying to identify a problem with my HP Pavillion dv7 laptop
    Several months ago it started getting hot and showing messages about problems with the internal fan and battery. It would say enter = shutdown and shut off. I suspected a bad battery so I checked it without it just plugging it in with the power cable. It seemed to work better so I assumed that was the problem.
    I ordered a new battery and it worked for a while. The problem came back and is getting worse. I can run it without the battery for a while but it gets got and shows the same message.
    I read on here that flashing and updating the bios worked for some but the latest update gives me an error IHISI not support BIOS then Insyde flash not supported.
    any help would be great this PC has a lot of info on it and I dont think it is a lost cause
    thanks

    Hi duddy, sorry to hear that you are having issues with your computer over heating.  I have found a document that will assist you with Restoring the BIOS.  http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&dlc=en&docname=c02693833&lc=en&product=5199538&tmp...
    I have also found a document that will assist you with Troubleshooting and Overheating and Auto shutdown issue.    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&dlc=en&docname=c03904182&lc=en&product=5199538&tmp...
    If you are still having issues, please let me know and I will be happy to offer more assistance..
    Thank you.
    Click the “Kudos Thumbs Up" at the bottom of this post to say “Thanks” for helping!
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    W a t e r b o y 71
    I work on behalf of HP

  • Why do I get "Evaluation Expired" message in MAX with Switch Executive

    Why do I get �Evaluation Expired� message in MAX with Switch Executive on a PXI rack, which has a �Ghosted� image from and identical PXI rack(no problem with this PXI rack), when logged in as USER in Windows2000, but not when logged in as a Local Administrator. When logged in as Administrator in Windows2000 running a TestStand sequence, using a �C� code action step calling the nise.dll is ok, but not when logged in as local user. The alias switch name is unknown.

    1.0.4.109 is a dll version number where as 1.0.2 is a NISE version number. The dll version number does not always line up with the product version number.
    NISE 1.0 has a dll version of 1.0.1.109
    NISE 1.0.1 has a dll version of 1.1.4.1
    NISE 1.0.2 has a dll version of 1.2.4.7
    NISE 2.0 has a dll version of 2.0.0.45154
    The best way to find the product number is to launch the application and click on Help and About. You NISE version is probably 1.0 and NISE 1.0.2 will fix your licensing problem.

  • I tried down loading mozilla firefox to use as a web browser. It was downloaded 100% then when prompted to "run" the error message comes up with a red cross and the message'This file is corrupted" and won't let me proceed. What do I do now?

    I tried down loading mozilla firefox to use as a web browser. It was downloaded 100% then when prompted to "run" An error message comes up with a red cross and the message'This file is corrupted" and won't let me proceed. What do I do now?

    It is possible that your anti-virus software is corrupting the downloaded files or otherwise interfering with downloading files by Firefox.<br />
    You can try to disable the real-time (live) scanning of files in your anti-virus software temporarily to see if that makes downloading work.
    See http://kb.mozillazine.org/Unable_to_save_or_download_files

  • How to delete the messages from sxmb_moni with status cancelled

    Hi ,
    how to delete the messages from sxmb_moni with status cancelled
    Is there any report for this
    Regards
    Suman

    I think just for deleting the jobs you can do this only
    Scheduling Delete Jobs
    To schedule delete jobs, proceed as follows:
           1.      In the Integration Engine -
    > Administration menu, choose Schedule Delete Jobs.
           2.      Select the job(s) to be scheduled.
           3.      Specify the start time and date.
           4.      Specify the period you want to use and choose Schedule.
    For an overview of all jobs, choose Jobs.

  • HT3529 Is there a way to create, store and use preset messages for use with "Messages"?

    Is there a way to create, store and use preset messages for use with "Messages". I often have a recurrinig message to send, after a repeating event, and need to enter the same short message each time. It would be nice to have this short message stored and selectable so that I do not need to enter each time.

    found an answer that seems to work:
    https://discussions.apple.com/message/17997300#17997300

  • Is it possible for me to swap out the apple logo in the message screen saver with my company's logo If so, how? Thanks!

    Is it possible for me to swap out the apple logo in the message screen saver with my company's logo? If so, how? Thanks!

    How long will my iPod service take?
    If you choose to use the Online Service Assistant, or service via Apple Technical Support: If your iPod is not personalized, you can expect service to be completed within approximately one week from the time you send your iPod to Apple. If your iPod is personalized, you can expect service to be completed within approximately ten calendar days from the time you send your iPod to Apple.
    Attention iPod shuffle customers: Service for iPod shuffle is performed by means of an express replacement program, via Online Service Assistant or Apple Technical Support. For more details, please review the Express Replacement Service tab on the left.
    Above from:
    Apple - Support - iPod - Service FAQ
    If it is caused by a hardware problem there is nothing you can do to prevent it from recurring unless it was caused by abuse like from dropping the iPod.
    Otherwise make sure you ask apple how they fixed. it.

Maybe you are looking for

  • Will baby oil kill macbook pro? It is still working and I do not know if I should do anything orr just pray?

    In a bedroom accident, the wife and I spilled baby oil into my MacBook Pro. (let the jokes begin) Amazingly, it still works fine. I know that is a scented mineral oil and that it is not too conductive. I took it to our local apple dealer, who said it

  • How do you modify the default Execute thread count in Weblogic Server 9.2?

    How do you modify the default Execute thread count in Weblogic Server 9.2? How can you tune the starting number of weblogic.ExecuteThread on server startup and/or set minimum number? Is there an option from the console? Please let me know. Thanks

  • Edited video file name now cant open in other programs

    Opened a MPEG video file in HP MediaSmart video Main program and edited the file name. Now when I try to open the file it will not open in Windows Media player or my other video edit/programs.  I did not make a copy of the file or do I have a backup,

  • Java Cryptographic Extension

    Hi Forum, Just commenced an academic project on Cryptography in Uni today and started studying some materials. I have tried to import SunJCE into my java class by specifying the statement "import com.sun.crypto.provider.SunJCE" in an enclipse work sp

  • Blank page issue in adobe forms

    dear expert, i have pdf form of 13 pages having many subforms in one of the subforms i am adding the row dynamically by a button add button . The row is being added but what is problem,when addition of row reaches to end of page it creates the blank