Powershell has the Add-Content cmdlet to append data to the end of a file. While it also has Export-CSV cmdlet, that seems to be more for dealing with collections where you pipe a collection of objects directly to the CSV (Comma Separated Value) file. What if you have several variables and you want to put them in a CSV file, one row at a time?

In my application, I just needed to log the creation of a Video and it’s status (Success, Failure…) along with the current date/time, the keyword for that video, and the filename of the video. So I created a small 5 line function to the work, and then call it from different places in my application.

I simply create the $newRow, i.e. the row or line of text to be written to the CSV. I handle add the commas myself, to make it a proper CSV.

The advantage of a CSV file is of course that it can be opened with most any spreadsheet tool, such as Microsoft Excel.

function AddToCSV($filename,$result,$action,$keyword,$videoFilename){
    $showDate = get-date
    $newRow = "$showDate,$result,$action,$keyword,$text"
    Add-Content $filename $newRow

#Sample Test Logic

$myFileName = "c:\Users\neal.walters\Documents\test.csv"

AddToCSV $myFileName "Success" "CreatedVideo" "best appliances in Abilene TX" ""
AddToCSV $myFileName "Failure" "CreatedVideo" "best appliances in Irving TX" ""
AddToCSV $myFileName "Success" "CreatedVideo" "best appliances in Farmers Branch TX" ""
AddToCSV $myFileName "Success" "PostVideo" "best appliances in Farmers Branch TX" ""

If you have commas inside of your text fields, you would have to do a little more to do, i.e. surrounding each text field with quotes.

Below is a sample of data similar to the sample above.


The following example is available in the BizTalk SDK, and represents an 850 “Purchase Order Document”,  We will be describing some how to read this EDI data in this blog.

ISA*00*          *00*          *ZZ*THEM           *ZZ*US             *991221*1226*U*00401*000000025*0*T*&gt;
PER*AA*Andrew Carlson*TE*(708) 555-2930
PID*F****Uninterruptible Power System
PER*AA*Camilla Anderson*TE*(708) 555-2011
PID*F****High Volume Printer Stand
PER*AA*Miranda Cappelan*TE*(708) 555-1111
PID*F****Electronics Cabinet Package (56" High)

After installing BizTalk, this file can be found here: “c:\Program Files (x86)\Microsoft BizTalk Server 2010\SDK\EDI Interface Developer Tutorial\ProcessEDI_TestLocations\SamplePO.txt”. It is part of the SDK (Software Developers Kit), which includes common usage scenarios of BizTalk.

A list of the common EDI X12 message can be found here on Wikipedia.

I did the following Google search beg03 x12 401, which resulted in several companies providing public PDF descriptions describing their requirements for sending or receiving 850 documents. For example, this 850 document was very useful in describing how to break down the above 850 message.

In the above sample document, the asterisk “*” is used as the primary separator character. Each line begins with a two or three character prefix (for example, ISA, GS, ST, BEG, etc… called a Segment Identifier (thus each line is a “Segment”). One advantage of XML over EDI is that every data value is identified by an name (either an element or attribute). When looking at an EDI document, you have to have the “decoder” ring or past experience to interpret the document by just looking at it.

Here’s a short clip from the above PDF document.  That document is an “Implementation Guide” which gives the specifics about how two companies should implement the more general standard.


Sample EDI 850 Implementation Guide


For example, in the above you see “PO1*2*25*EA*35.68**CB*1093-4927-001”.
Each data value is given a name based on the Segment ID and then followed by a two digit position. So for example, the first field of interest to us is PO102, which is the “Quantity Ordered” which has a value of 25. PO103 is the “Unit or Basis for Measurement Code”. Looking at the EDI values, we see “BX”, “EA”, and “PC” on different P01 segments, with specifically the value of “EA” on the segment we are looking at. It’s not shown in the above clip, but you might guess that is PO104 is the price (value of 35.68), because it has two decimal places.

When you see several asterisks side by side, that means that a field value in between has been omitted.So PO105 is missing or null, and PO106 has the value of “CB” for the “Product/Service ID Qualifier”. Note that in the above PDF, that specific company accepts three values MF, MG, VP, so obviously our document from the BizTalk sample library was not specific to the rules of the specific company providing that PDF.

BizTalk internally treats all messages as XML, allowing them to be mapped with the BizTalk mapper (which is actually XSLT under the cover). It is the BizTalk Adapter specified in the Receive Pipeline that converts the EDI data to XML data. Below is an example of a BizTalk map in the SDK, showing the mapping of the P01 segment to an internal XML format with more meaningful names:

BizTalk EDI Map for 850

BizTalk EDI Map for 850