# 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: 5915 # x-archived: 2015-07-03T01:44:43 # x-published: 2015-07-01T12: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 }