Geeks With Blogs
Cogito Ergo Code If I don't put it here - I will surely forget!

I really like TDD (Test Driven Design) and like to push messages through the system as soon as possible.

I have really enjoyed using Powershell to drive the input of XML files into file receive locations. Here are two of the simplest recipes.

Repeatedly dropping the same file

This will copy a single file one hundred times, each with a different numeric filename (i.e. 1.xml, 2.xml, etc...)

for($i = 0; $i -le 100; $ += 1)
    Copy-Item .\SampleMsg.xml C:\FileDrop\IN\msg_$i.xml
    if($i % 10 -eq 0) { $i }

# this is a MS-DOS PAUSE command equivalent
Write-Host -NoNewLine "Press any key to continue"
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""

Dropping Templated variants from a CSV data file

We have a simple template XML file that contains the following:

<ns0:UnaryMathsRequest xmlns:ns0="">

We also have a CSV file that contains the following:

AAAA.xml,ACME Holdings,Factorial,2.0
AAAB.xml,Ludite Enterprises,Inverse,2.34
AAAC.xml,Quaint Commerce,Squared,34.3

We can use this Powershell script to drop named copies of the files into the drop location.

$files = Import-Csv .\DataFile.csv
for-each($line in $files)
  $template = [xml](get-content .\TemplateFile.xml);
  $template.UnaryMathsRequest.SourceName = $line.SourceName;
  $template.UnaryMathsRequest.Operation = $line.Operation;
  $template.UnaryMathsRequest.Variable = $line.Variable;

  $out = $template.get_InnerXML();
  $path = "C:\FileDrop\IN\" + $line.FileName;

  set-content $path $out;

Voila! Three files duly copied to the receive location.

Posted on Friday, February 20, 2009 8:40 PM BizTalk , Powershell | Back to top

Comments on this post: Powershell and BizTalk testing (Mk 1)

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Howard Ricketts | Powered by: