PoshCode Archive  Artifact Content

Artifact fb72fe1f50e2b77a3210a177f7f4605c69d8403970d994cb5ef1424b99268691:

  • File Templates-and-Tables.ps1 — part of check-in [f7997aa94b] at 2018-06-10 14:01:55 on branch trunk — This script generates an output file from a template and a driver table. Both of the inputs are files. The template file contains plain (user: Walter Mitty size: 1296)

# encoding: ascii
# api: powershell
# title: Templates and Tables
# description: This script generates an output file from a template and a driver table.  Both of the inputs are files. The template file contains plain
# version: 0.1
# type: script
# author: Walter Mitty
# license: CC0
# x-poshcode-id: 5813
# x-archived: 2015-04-05T23:54:20
# x-published: 2015-04-04T12:00:00
#
# text and embedded variables.  The driver table has one column for each variable, and one row for each expansion to be generated.
#
<#  This scriptlet is a table driven template tool. 
    It's a refinement of an earlier attempt.

    It generates an output file from a template and
    a driver table.  The template file contains plain
    text and embedded variables.  The driver table has
    one column for each variable, and one row for each
    expansion to be generated.

    2/15/2015
  
#>

param ($driver, $template, $out);

$OFS = "`r`n"
$list = Import-Csv $driver
[string]$pattern = Get-Content $template
Clear-Content $out -ErrorAction SilentlyContinue

foreach ($item in $list) {
   foreach ($key in $item.psobject.properties) {
      Set-variable -name $key.name -value $key.value
      }
   $ExecutionContext.InvokeCommand.ExpandString($pattern)  >> $out
   }