Saturday, November 27, 2010

Retrieving message counts of a remote MSMQ queue using PowerShell

My current client does work for the retail industry. This weekend is the beginning of the holiday shopping season, a very important period to the retail industry.

This is also the first time that I’ve seen the planning and operations that the Retail IT groups go through. I’m really impressed by the amount of planning and support that is in place to make sure that IT-related issues don’t interfere with holiday shoppers. There are bridge calls that begin at 2am, around the clock monitoring of servers, hourly reports, call-ins every 30 minutes and lots of people are either active or on-call.

My part in this was to spend three hours monitoring 13 remote servers. To make life a little easier, we used a PowerShell script similar to this to retrieve the queue lengths of some remote MSMQ queues.

   1: $queuesToCheck = 'Q1' , 'Q2'
   2: $servers = 'myserver1', 'myserver2'
   3:  
   4: $queues = @()
   5: $servers | ForEach-Object {
   6:     $ServerName = $_
   7:     
   8:     $machineQueuesToCheck = $queuesToCheck | ForEach-Object { "$ServerName\$_".ToLower() }
   9:     $queues += gwmi -class Win32_PerfRawData_MSMQ_MSMQQueue -computerName $ServerName  | Where-Object {
  10:         $machineQueuesToCheck -contains $_.Name.Trim() -and $_.MessagesInQueue -gt 0
  11:     } 
  12: }
  13:  
  14: $queues | Format-Table Name, MessagesInQueue

Monday, September 6, 2010

Ascendo DataVault & Blackberry Desktop Manager v6

I’ve been a Blackberry Storm 9530 owner since the device was released. I’ve been really happy with the device, especially with the application ecosystem. There are lots of apps for the device. (There are a lot of apps for Blackberry devices in general).

As a computer professional, I spend a lot of time on the Internet. I’m a member of a large number of sites and that leads to a lot of username/password combinations to keep track of. An app for tracking passwords is a necessity for me. I don’t have the memory to track them all. Single-sign-on can’t come fast enough.

So I tried a bunch of password apps and ended up with DataVault from Ascendo, mainly due to its flexibility and the fact that there is a version that runs on Windows and the Blackberry Storm. The two versions will sync between each other through the Blackberry Desktop Manager.

This worked well until about a month ago when RIM released v6.0 of the Desktop Manager. According to an FAQ on Ascendo’s site, RIM removed an API that Ascendo was using to support synchronization. Unfortunately I didn’t notice that synchronization was broken until today.

The FAQ suggest upgrading to the latest version, 4.7.1 which has a fix for the problem. Still no syncing for me.

Another FAQ suggests upgrading the device version to the latest. Still no syncing for.

On a whim, I try running the Desktop Manager as Administrator. Surprise! The sync dialog appears.

Only two hours lost.

Sunday, August 29, 2010

Register Spring.Net objects with code

Anyone that has worked with Spring.Net is probably familiar with configuring the IOC container using an XML document. A typical example would be:

   2:  
   3: <objects xmlns="http://www.springframework.net" 
   4:          xmlns:v='http://www.springframework.net/validation' 
   5:          xmlns:aop="http://www.springframework.net/aop" 
   6:          xmlns:db="http://www.springframework.net/db" 
   8:  
   1: <?xml version="1.0" encoding="utf-8"?>
   9:   <object id="ConsoleWriter" type="SimpleCalculatorWithComplexTree.Writers.ConsoleWriter" singleton="false" >
  10:     <constructor-arg name="formatter" ref="HexFormatter" />
  11:   </object>
  12:  
  13:   <object id="Calculator" type="SimpleCalculatorWithComplexTree.Calculator" singleton="false">
  14:     <constructor-arg name="writer" ref="ConsoleWriter" />
  15:   </object>
  16:  
  17:   <object id="HexFormatter" type="SimpleCalculatorWithComplexTree.Formatters.HexFormatter" singleton="false" >
  18:     
  19:   </object>
  20:   
  21: </objects>

The last couple of years has seen an anti-XML movement begin to form. In the world of IOC containers, this has materialized as a movement away from XML configuration and more towards using code constructs and “convention over configuration.” I’m not against XML. After all, almost everything has a place.


I recently did a presentation on Spring.Net for a .NET user group. I wanted to introduce the IOC container without overwhelming people with XML. A quick search found an article about XMLless configuration of the container. This approach felt like it would be a distraction from my goal of getting to the container.


Luckily I stumbled into at article from early 2008 that discussed the configuration api. From this I was able to create this method that extends the GenericApplicationContext and allows for easy registration of a type in the container:



   1: Imports System.Runtime.CompilerServices
   2: Imports Spring.Context.Support
   3: Imports Spring.Objects.Factory.Support
   4:  
   5: Public Module SpringExtension
   6:  
   7:     <Extension()>
   8:     Public Sub RegisterType(Of T)(ByVal ctx As GenericApplicationContext, ByVal builderConfig As Action(Of ObjectDefinitionBuilder))
   9:         Dim objectDefinitionFactory As IObjectDefinitionFactory = New DefaultObjectDefinitionFactory()
  10:  
  11:         Dim builder As ObjectDefinitionBuilder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, GetType(T))
  12:         builderConfig.Invoke(builder)
  13:  
  14:         ctx.RegisterObjectDefinition(builder.ObjectDefinition.ObjectType.Name, builder.ObjectDefinition)
  15:  
  16:     End Sub
  17:  
  18: End Module

Here’s a quick example of its use:



   1: Dim ctx = New GenericApplicationContext()
   2:  
   3: ctx.RegisterType(Of Calculator)(Sub(b As ObjectDefinitionBuilder) b _
   4:                               .SetAutowireMode(Spring.Objects.Factory.Config.AutoWiringMode.AutoDetect) _
   5:                               .SetSingleton(False))
   6:  
   7: ctx.RegisterType(Of HexFormatter)(Sub(b As ObjectDefinitionBuilder) b _
   8:                       .SetAutowireMode(Spring.Objects.Factory.Config.AutoWiringMode.AutoDetect) _
   9:                       .SetSingleton(False))
  10:  
  11: ctx.RegisterType(Of ConsoleWriter)(Sub(b As ObjectDefinitionBuilder) b _
  12:                       .SetAutowireMode(Spring.Objects.Factory.Config.AutoWiringMode.AutoDetect) _
  13:                       .SetSingleton(False))

Sunday, August 22, 2010

Disable password expiration on Windows Hyper-V server

Back in April I wrong a quick entry about not being able to use the Hyper-V Remote manager to access the Hyper-V server. I was getting the error “Cannot connect to the RPC service on computer…” because my credentials on the server had expired. Today I finally got around to changing the account security policy on the server to prevent password from expiring. The command is:

NET accounts /MAXPWAGE:UNLIMITED

Monday, August 16, 2010

Spring.Net and Common.Logging 2.0

Versions 1.2 and 1.3 of Spring.Net bind to Common.Logging 1.2. If you are using or need to use v2.0 of Common.Logging, you can use an assembly redirect to force the assembly loader to the updated version. Put the following into your application’s configuration file:

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Common.Logging"
publicKeyToken="AF08829B84F0328E" />
<bindingRedirect oldVersion="1.2.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Sunday, May 30, 2010

TF31002, VS2008 and TFS2010

It’s funny (but not at the time) how easily you can find the answer to a question once you’ve already answered the question.

Last Friday I spent way too much time trying to figure out why I was getting the error TF31002 when trying to connect my Visual Studio 2008 instance to Team Foundation Server 2010. I knew you could do it. I have the configuration running at home. I have multiple co-workers with successful configurations. Yet, on these two machine, nothing but TF31002.

Today I can search and find all kind of solutions as long as I don’t include TF31002 in my search. Searching with the terms ‘VS2008 TFS2010’, returns the solution as the first hit. Search on TF31002 gets nothing useful. That’s why I put TF31002 in the title of this post.

The setup:

VS2008 with SP1 already installed.

We installed TFS2010.

We then installed Team Explorer for VS2008 and the Visual Studio Team System 2008 Service Pack 1 Forward Compatibility Update for Team Foundation Server 2010 (Installer). I tried to get to the TFS2010 box and received the error TF31002. Oh. I was told that you’re supposed to include the url to the team project :

http://server:8080/tfs/collection

That got me an nice message about not allowing ‘http:’, ‘https:’ nor ‘/’ in the server name.

Sound familiar?

Sadly, the answer is in the sequence of the installs. Since I installed Team Explorer after installing VS2008 SP1, I had to reinstall SP1 and then the Forward Compatibility Update.

Sunday, May 9, 2010

Creating a NetBIOS alias for the local machine

My current assignment is with a client that has a system consisting of multiple components where each component is a separate .EXE. This wouldn’t be so bad except for the configuration problem that is created. Each component has its own config file and there is a requirement for some consistency between the config files for some values. In addition, the system is deployed to multiple environments and clients.

Configuration is a nightmare and we’re still doing it manually.

This past week, one of the team members thought of the idea of using aliases instead of referring to actual machine names (for file and application location). The thought was that we could define the aliases in the Hosts file and reference the loopback address (127.0.0.1).

Eh, no.

Using the Hosts file works well for HTTP but has no affect on UNC paths.

Luckily this client has an infrastructure group and they were able to help us out. They identified four registry entries that have to be changes in order to create aliases for the local machine.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters Add a new Multi-String value called OptionalNames. Enter one or more aliases, one per line.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters Add a new DWORD value called DisableStrictNameChecking and set to 1.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters Add a new DWORD value called DisableLoopBackCheck and set to 1.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
Add a new Multi-String Value BackConnectionHostNames. Enter one or more aliases, one per line.

You’ll have to cycle the machine for the configuration to take affect.