PowerShell for BizTalk Server

by Matt Milner 26. June 2008 17:29

During my preparation for my Tech Ed talk on BizTalk Server port binding options, I wanted to write a PowerShell script to help me manage the transitions from one demo to another.  For the most part, I was looking for a way to quickly enable / disable receive locations and start / unenlist send ports and orchestrations.  All of this is available in WMI, but I wanted to make some reusable functions in PowerShell so I didn't have to drop into WMI each time I wanted to do it.  I wanted a simple function I could call like so:

EnableReceiveLocation("MYRL")

 

It turns out that creating these functions in a script file is relatively easy.  One issue I ran into, however, is that transitions for send ports and orchestrations are not as straight forward as they are in the UI.  In the UI if a port is unenlisted, I can simply start it.  Under the covers, however, the admin tool is actually enlisting and then starting.  So, in code, I have to call the operations to both enlist and start.  Or, if the port is already enlisted, but not started, then in a function called StartSendPort, I have to just start it.  So there is some checking of the current status rather than just blindly wrapping WMI calls.  You'll need to check the docs in some situations to get the enum values.  I used the hard coded values in my case. 

 

function StartSendPort{
    param([string]$portName)

    $sp = Get-WmiObject MSBTS_SendPort -n root\MicrosoftBizTalkServer -filter "Name='$portName'"

    if($sp -ne $null)
    {
        if($sp.Status -eq 1 -or $sp.Status -eq 2)
        {
            if($sp.Status -eq 1)
            {
                $null = $sp.Enlist()
            }
            $null = $sp.Start()
            Write-Host "Started send port: " + $portName -fore Green
        }
        else
        {
            Write-Host "Send port " + $portName + " is already started." -fore Yellow
        }
    }
    else
    {
        Write-Host "Send port not found" -fore Red
    }
}

 

Where things got a little more challenging was when I wanted to start working with applications.  Applications provide a nice way to manage a group of ports by allowing start/stop functionality; unfortunately, the application is not surfaced through WMI.  Never fear however, b/c PowerShell is built on top of .NET.  All I needed to do was create an instance of the BtsCatalogExplorer class and then I was on my way to managing the applications.  But first, I had to load the assembly that included that class.  I chose to do that using the path, but strong names works very well too.  Then I used the New-Object cmdlet to create an instance and navigate to the application. 

 

[System.Reflection.Assembly]::LoadFrom("C:\Program Files\Microsoft BizTalk Server 2006\Developer Tools\Microsoft.BizTalk.ExplorerOM.dll")

function StopBTSApplication
{
    param([string]$appName)

    $exp = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
    $exp.ConnectionString = Get-BTSConnectionString
    $app = $exp.Applications[$appName]
    if($app -eq $null)
    {
        Write-Host "Application " $appName " not found" -fore Red
    }
    else
    {
        if($app.Status -ne 2)
        {
            #full stop of application
            $null = $app.Stop(63)
            $null = $exp.SaveChanges()
            Write-Host "Stopped application: " $appName
        }
    }

}

 

And, because I was trying not to hard code too much, I create the connection string using WMI to get the group settings. 

function Get-BTSConnectionString
{
    $group = Get-WmiObject MSBTS_GroupSetting -n root\MicrosoftBizTalkServer
    $dbName = $group.MgmtDBName
    $server = $group.MgmtDBServerName
    [System.String]::Concat("server=", $server, ";database=", $dbName, ";Integrated Security=SSPI")
}

 

Notice that I simply execute the Concat to get the connection string, and because this results in a new string, that value is returned to the pipeline and available to be set in a variable or used in a cmdlet. 

I'm loving the stuff I can do with PowerShell and feel like I'm just scratching the surface.  Hope this helps someone else get a jumpstart as well.  I've attached the PowerShell file with my functions included. 

Attachment: BizTalk_PowerShell.ps1.txt

Tags:

BizTalk Server

My Tech Ed Demos

by Matt Milner 6. June 2008 20:29

Thanks to everyone who came to my session on port binding options in BizTalk Server yesterday.  You can find the demos here including the visual studio solution, binding files for BizTalk and the PowerShell script I used for setting up and running my demos. 

Tags:

BizTalk Server | General Musings

Is support coming for BizTalk builds on TFS?

by Matt Milner 12. May 2008 12:54

According to Brian Harry[1] , he has been working with the BTS folks to get this put in place.  He has been assured that this will be part of the R3[2] release of BizTalk Server that is due out next year.  Finally, automated builds for BizTalk without all the hassle, I hope this definitely makes it into the product, as right now it is one more thing that makes people think BizTalk is not for .NET developers. 

 

[1] BizTalk Support with TFS

[2] http://blogs.msdn.com/stevemar/archive/2008/04/23/biztalk-server-platform-updates.aspx

Tags:

BizTalk Server

Spaghetti Code Podcast - Connected Systems

by Matt Milner 12. May 2008 10:56

I got a chance a few weeks ago to sit down with Jeff Brand at the local Microsoft office and talk about something I love - Connected Systems.  We discussed Workflow and Biztalk, WCF and web services and how it all fits together.  Jeff is fun to talk to and does a good job of asking questions that developers are interested in.  The issues most developers face when building connected systems and trying to pick technologies were especially fun to discuss.  If you are interested, check out the audio - http://www.slickthought.net/post/2008/05/Spaghetti-Code-Podcast---Matt-Milner-on-Connected-Systems.aspx.

You can also check out some of his other podcasts with more Minneapolis folks on a range of topics: http://www.slickthought.net/category/SpaghettiCode.aspx

 

Enjoy!

Matt

Tags:

BizTalk Server | Windows Workflow Foundation | Windows Communication Foundation

Applied BTS R2 in the Windy City

by Matt Milner 10. April 2008 09:00

I've been teaching mostly WF and WCF lately, so I'm excited that in a couple of weeks (April 22) I'll be getting a chance to teach our core BizTalk course again in the lovely city of Chicago.  I'm excited because there is a lot of cool stuff for this particular open enrollment. 

1) R2 - need I say more? I will.  We will be using the latest bits to teach the core course from now on so you'll be learning BizTalk Server fundamentals using the latest and greatest version.  This is still a class for developers new to BizTalk, so if you have taken this class, you might be interested in the R2 features class that Jon is teaching in May and August. 

2) Dual Monitors!  Our crack sales team has negotiated dual monitors from the hardware vendor so you'll be able to see the lab manual and Visual Studio each in full screen glory!

3) It's in downtown Chicago right on Wacker Drive near all sorts of cool stuff for the evenings.

4) It's BizTalk and we'll cover all the three letter acronyms (TLA) BRE, BAM, WCF,WSE,ASMX (ok that's four letters), CSV, HAT, PUB (actually a technical term, but maybe where we'll be in the evenings as well), SUB, EAI, ESB, SOA.  I could go on, but you get the picture. 

5) As if all the above are not enough, we have some seats available and the course is in a week and half, so the sales guys are "ready to deal".  Actually, their just ready to cut you some discounts :) , especially if you sign up two or three people together, but even if you are just signing up one developer.  Talk to our fabulous sales team to get more information or register with a discount.  Just tell them you read about it on my blog. 

Hope to see you there, and once I get back from the class, I promise some more technical content.  I've been working on some demos and samples that I'll be posting over the next couple of months. 

Tags:

BizTalk Server | General Musings

Disappearing BizTalk Add Generated Items wizard with SQL adapter

by Matt Milner 12. February 2008 22:59

I've run into this in two different places now so I figured it was time to blog about it and hopefully help someone else out since I didn't see much about this on the web when searching.  What I experienced was that when I would try to add a schema for a table in SQL Server, the wizard would get part way through allowing me to configure it, and then it would just disappear (usually when I hit the next button after specifying the select state or when I was about to choose the tables for an updategram) with no errors in the UI or in the event log.  I have seen this in two different cases. 

In the first case, and easiest to fix, I was trying to access tables to create an updategram, but all of the tables names belonged to a schema other than the DBO schema.  Every time I tried to create the updategram, I would say I wanted to do the updategram and then wizard would crash.  In this case, I was able to duplicate the database tables in another database (using scripting of the sql from the sql management tool) and put it in the default namespace.  Then I updated the schema by manually changing the node in the updategram that corresponded to the table name so that it contained the schema name.  After making this change, the updated schema worked fine against the database.  So it seems like the adapter can handle the non-standard schemas at runtime just fine, but not at design time. 

I should note that the above scenario was with BTS 06, not the R2 release.  I haven't determined if this is still an issue in the latest bits. 

The other scenario where I ran into this problem was with a BizTalk solution that had been created in BTS 06 and which I was now opening with BTS 06 R2.  In this situation, I was creating a receive location and after I entered the select statement, the wizard would bail on my with no warnings or errors.  I'm still not sure why this one was happening, but here is what I did to get it working. I created a new empty BizTalk project in a brand new solution and used the wizard to generate the items, which worked fine for some reason.  Then I went back to my old solution and tried again and it worked.  I'm surmising that running the wizard once on a new project allowed the problem to be fixed, some update or reg setting tweaked with the new project type, but I don't really know, it could have been a fluke of some sort for all I know.  The end result is that now my wizard appears to be working fine with new and updated projects. 

Tags:

BizTalk Server

Microsoft announces next big wave of products "Oslo"

by Matt Milner 31. October 2007 14:00

I attended the Microsoft SOA and BP conference this week in Redmond where they announced their plans for future of connected systems (the division responsible for BizTalk, WCF, WF, AD, and much more).  You can read more about the announcement and what impacted products are on the Microsoft SOA site.  What I found most interesting is that this effort is not just about the Connected Systems Division (CSD) but also includes the Developer Division with the next release of Visual Studio and the .NET Framework, as well as the System Center products.  The close alliance of those product groups is something we don't often see from Microsoft and can only be better for customers as we'll get a better story about using those products together. 

Now being a BizTalk/WCF/WF guy, I'm pretty interested in how all of those technologies get impacted by the modeling and management tools as well as how the integration of these technologies continues to improve.  It's only going to get better, but like all technology, we'll continue to have things to learn and understand about these technologies and how they get leveraged in different environments. 

Most interesting to me is that the keynote included information stating that CTPs and Betas would be available in 2008. That makes this stuff much more real for the near term than say a 5 year timeline.  Microsoft obviously won't be able to create the entire vision in a single release of each product, but the next phase is pretty exciting and being able to get your hands on the technology and see what they are doing and thinking can be critical as you plan for your future projects.  It's also a great way to give feedback and help direct the product team about what is important to you as a customer. They really do listen, even if you don't always get exactly what you want, significant changes happen based on customer feedback.  

We also had our two day pre-conference training on the new features in BizTalk R2 and .NET 3.5.  In addition we had some fun talking about "Astoria" and BizTalk Services which are emerging technologies built on WCF and other CSD technologies that provide some really compelling options for messaging and data access.  The class went really well and we're thinking about making it available as a seminar course for people who want to get a good deep dive into the broad range of technologies.  Let us know if you are interested in the class for your company. 

Tags:

BizTalk Server | General Musings | Windows Workflow Foundation | Windows Communication Foundation

BizTalk Mapper/XSLT - Creating sequence number based on destination tree

by Matt Milner 25. October 2007 10:48

When creating maps in BizTalk server, or generally creating XSLT transforms, you might run into a situation, as I did, that calls for you to generate a sequence number in your destination document.  If the source document and destination have a similar repeating structure, you can always use the Iteration Functoid or the position() function to create a sequence based on the source tree.  I recently ran into a situation where I needed to create a sequence number for the output records, but I was conditionally mapping the input records.  For example, I had a structure like the following for my source:

<Invoices>

  <Invoice>

    <InvoiceDetail>

       <SomeFlag>true</SomeFlag>

    </InvoiceDetail>

    <InvoiceDetail>

       <SomeFlag>false</SomeFlag>

    </InvoiceDetail>

</Invoice>

  <Invoice>

    <InvoiceDetail>

       <SomeFlag>false</SomeFlag>

    </InvoiceDetail>

    <InvoiceDetail>

       <SomeFlag>true</SomeFlag>

    </InvoiceDetail>

</Invoice>

</Invoices>

In my output, I actually had a similar structure, but I was only creating output records for the items where the "someFlag" element was true.  So in each case in the example, I'd only have one detail record for each invoice rather than two.  In the first case, creating a sequence number based on the position() function or Iteration functoid would work just fine.  However, in the second Invoice, my sequence would start with 2 since that is what the position() function would return.  This really gets fun when you have multiple details and your sequence starts skipping positions.  I was getting sequences like 1,4,10,13. 

What I needed was a way to generate the number based on the destination tree, not the source; enter xsl:number.  Using xsl:number you can provide a value and do some formatting, etc., but I was more interested in using it without submitting a value which causes a new number to be generated. If you look at the MSDN documentation for xsl:number you'll see that you can specify more attributes to control how the number gets generated.  Specifically the "count" and "from" attributes allow you to scope the generation of the numbers and where to start, respectively.  These attributes allow you to generate the numbers as you want them in the output.  A lot of the examples I found on the web were for formatting numbering in lists or table of contents formats to number things like 1.1  or 1.A.  The "format" attribute really helps here, but I just wanted a raw number. 

I added a scripting functoid to my map and set the type to inline XSLT.  I then used the xsl:number like so (based on the sample document above). 

<xsl:number count="*[./s0:SomeFlag='true']" />

That got me all I needed. My sequence numbers in my output were only generated when an output detail was created and the sequences were unique to each invoice (i.e. they restarted for each invoice which is what I wanted).  In my case I didn't need to use any other controls on xsl:number but you might find that you need to further restrict it using the "from" attribute.  I'd start simple and then work from there. 

A couple of things to note.  First, the XSLT expression that I have in the "count" attribute points to all elements where the SomeFlag is true.  You may need to play around with this to get the right expression, just make sure you are referencing the right context (based on your XSLT) and filter the records appropriately.  Also notice that I used a namespace prefix on the SomeFlag element.  In the BizTalk mapper I needed to add this since BizTalk uses this prefix for the primary/first namespace of my source document.  Without this prefix, I always got empty output, so watch for this in your own code and use the validation map functionality in BizTalk to view the XSLT and see what prefixes you might need.  If you want to make sure things are working at a base level, then just use * for the "count" attribute and you should get a similar output as if you used the position() function.  Then apply filters from there to get the results you want. 

I couldn't find anything to really help me figure this out without some work, so hopefully this will save someone some time (or maybe you are just better at searching the web than I am). 

Tags:

BizTalk Server

BizTalk R2 class with Jon Flanders

by Matt Milner 2. July 2007 09:47
As many of you know, Jon Flanders recently joined us here at Pluralsight.  In just a couple of weeks Jon is going to be delivering our first public offering of the BizTalk R2 class.  If I weren't already committed, I'd be at this course as Jon has some great material on the new features in the upcoming R2 release including the integration with WCF / WF and all the cool RFID stuff.  Be sure to check it out if you are using or plan to use R2. 

Tags:

BizTalk Server | General Musings

Tech Ed Demos for WCF Adapter session and chalk talk

by Matt Milner 9. June 2007 03:21
For those of you who attended Tech Ed and wanted the demos from the breakout and chalk talk about the WCF adapter, you will find them below.  Thanks to all who attended, and enjoy. 
 
Breakout session (445 kb) (Connected Systems application) includes transaction flow example and basic adapter configuration. See the setup folder for db scripts and setup directions.
 
Chalk Talk (5.5 MB) -- includes three demos: BTS as WCF message router, WCF channel extensibilty in BTS (PO + line items = single transaction), and using BizTalk Services in the cloud (multi-cast vendor request).  Each demo should have an installer for the BTS portion and other files to update configuration etc. 
 
any questions, just add them in comments on this blog post, or contact me through this blog. 

Tags:

BizTalk Server | General Musings | Windows Communication Foundation