Search
Joe Pruitt - A Software Architect's take on Network Security
You are here: DevCentral > Weblogs

posted on Wednesday, January 14, 2009 10:21 AM

PowerShell Welcome to this addition of the PowerShell ABC's where you'll find 26 posts detailing a component of the PowerShell scripting language, one letter at a time.  Today's letter is the letter "Q" and there wasn't really much to go with.  We've got the "-Quiet" switch but that's fairly limited in it's usage.  I opted for it's support for the FIFO data structure: queues.

queue A queue is a particular kind of collection in which the entities in the collection are kept in order.  Operation on a queue are to add items to the end position and remove them from the front position. 

As a First-In-First-Out (FIFO) data structure, the first element added to the queue will be the first one to be removed.

There are many types of Queues that you can work with, including native .NET Queues, Windows Azure Queues, and IBM WebSphere MQs.

System.Collections.Queue

PowerShell doesn't have a native queue data type but that doesn't stop you from being able to build and manage one as the .NET framework has done that for us and since PowerShell has access to all of the .NET Framework classes, working with a queue is as easy as calling the New-Object Cmdlet on a System.Collections.Queue object.

PS C:\> $q = New-Object System.Collections.Queue
PS C:\> $q.Enqueue("one")
PS C:\> $q.Enqueue("two")
PS C:\> $q.Enqueue("three")
PS C:\> $q
one
two
three
PS C:\> $q.Dequeue()
one
PS C:\> $q
two
three
PS C:\> $q.Enqueue("four")
PS C:\> $q
two
three
four

Windows Azure Queues

Let's not stop with local queues, PowerShell allows you to access them in the cloud as well.  Windows Azure is the foundation of Microsoft's Cloud Platform and provides the building blocks for application developers to write scalable and highly available services.   One of those building blocks is the Windows Azure Queue which provides a reliable message delivery mechanism.  Microsoft has provided a "CloudDrive" sample that implements a PowerShell Provider to to enable command line access to Queue Storage resources.

PS C:\> queue:
PS queue:\> Get-ChildItem messagequeue
Name Msg Cat
---- -------
messagequeue 1
PS queue:\> $q = (dir messagequeue)
PS queue:\> $q | Get-Member
TypeName: Microsoft.Samples.ServiceHosting.StorageClient.QueueRest
Name MemberType Definition
---- ---------- ----------
Length AliasProperty Length = Size
Path AliasProperty Path = QueueUri
add_MessageReceived Method System.Void add_MessageReceived(MessageReceivedEv...
ApproximateCount Method System.Int32 ApproximateCount()
Clear Method System.Boolean Clear()
...

IBM WebSphere MQs

There are also other PowerShell libraries for Queuing systems out there.  IBM has released their Cmdlet's for WebSphere MQ.  Here's a great list of blog posts on a beginners guide to PowerShell for WebSphere MQ if you are interested in getting started.  With IBM's latest release, you can now manage queue managers across multiple servers from a single PowerShell workstation.  Here's a link to the PowerShell for IBM WebSphere MQ documentation.



Feedback

No comments posted yet.

Let Me Know What You Think


Please use the form below if you have any comments, questions, or suggestions.

Title:
 
Name:
 
Email: (so we can show your gravatar)
Website:
Comment: Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
 
Please add 3 and 2 and type the answer here:

Blog Stats

Posts:379
Comments:1067
Stories:1
Trackbacks:301
  

Article Categories

  iRules
  

Image Galleries

  

Joe's bookshelf: read

The Lost Gate
4 of 5 stars
This one started slow but I got really got into it about 1/3 of the way through. If you are an Ender's Game fan, you'll probably like this one as well.

goodreads.com


82,243 Members in 102 Countries and Growing!

Join DevCentral Today!

About DevCentral

DevCentral has been a successful, thriving community for many years. We have always strived to bring you the best technical documentation, discussion forums, blogs, media and much more that we can.

So dive in, get familiar with DevCentral. We hope you like it, we hope it makes your job easier, and lets you get that much more power out of the community. To learn more, make sure to check out the Getting Started section. And if you have any problems, or think something could be easier to use, drop us a line to let us know.

Got It !

We've received your comment and transmitted it directly to DevCentral HQ.

Thanks for taking time to let us know what's on your mind. At DevCentral | Community Matters!

Get In Touch With Us

Have questions, suggestions or just want to get something off your chest?

Use our handy form below to Direct Connect with DevCentral Mission Control.

Send Us Feedback       or