Often, after implementing a new system or application on BizTalk, we need to provide a report to management of how many files were processed.
If you keep an archive of all files in or out, you can use that with a simple PowerShell to accomplish the report. Here’s an example I found:
PowerShell Example 1 – Files by Date
<pre>
$count = @{}
$size = @{}
get-childitem d:\BizTalk\MyApp\Archive\EDI850Order\*.txt |
foreach {
$date = $_.lastwritetime.tostring('dd-MMM')
$count[$date]++
$size[$date] += $_.length
}
$count.keys |
sort|
foreach {
[PSCustomObject]@{
Date = $_
'Number of files' = $Count[$_]
Size = $Size[$_]
}
} | format-table -AutoSize
</pre>
Sample Results of Above Powershell
<pre>
Date Number of files Size
---- --------------- ----
08-Sep 14 37263
11-Sep 19 53761
12-Sep 7 26984
13-Sep 45 147575
14-Sep 44 154050
</pre>
Example 2 – Multiple Folders – Files by App and Date
<pre>
#################################################################
#
#
# Neal Walters - 09/25/2017
# Script: FileCountByDateAllDirs.ps1
# Purpose: Get a summary report of files processed
# by each app on each date
# based on archive files
#
#################################################################
cls
$count = @{}
$size = @{}
$items = @(Get-ChildItem 'd:\BizTalk\EDIHorizon\Archive\EDI850Order' -r)
$items += @(Get-ChildItem 'd:\BizTalk\ZLien\ArchiveOutbound' -r)
$items |
foreach {
$posFirstSlash = $_.fullname.indexOf("\")
$posSecondSlash = $_.fullname.indexOf("\", $posFirstSlash+1)
$posThirdSlash = $_.fullname.indexOf("\", $posSecondSlash+1)
$lenApp = $posThirdSlash - $posSecondSlash - 1
# Write-Host $app $posSecondSlash $posThirdSlash $_.fullname
$date = $_.lastwritetime.tostring('yyyy-MMM-dd')
$app = $_.fullname.substring($posSecondSlash+1,$lenApp)
$key = $app+" "+$date
$count[$key]++
$size[$key] += $_.length
}
$count.keys |
sort|
foreach {
[PSCustomObject]@{
App_Date = $_
'Number of files' = $Count[$_]
Size = $Size[$_]
}
} | format-table -AutoSize
</pre>
Sample Results of Above Powershell
<pre>
App_Date Number of files Size
-------- --------------- ----
App1 2017-Sep-18 35 119159
App1 2017-Sep-19 32 105811
App1 2017-Sep-20 35 116315
App1 2017-Sep-21 12 34450
App1 2017-Sep-22 24 85952
App2 2017-Sep-20 2 15460798
App2 2017-Sep-21 2 15457187
App2 2017-Sep-22 2 15472012
</pre>