The properties of a file should be exported to a text file using a template.


The first step is to create a template, the format of the template is quite flexible. In this example the following html template is used:

 <table border="1">
   <td>{Created By}</td>

The following script will then replace the property names with their corresponding values:

$templatePath = "C:\temp\template.txt"
$destinationPath = "C:\temp\template.html"

$regex = [regex]"\{+(?i)\b[A-Z\s]+\b\}"
$template = Get-Content -Path $templatePath
$propertyMatches = $regex.Matches($template)
foreach($propertyMatch in $propertyMatches){
    $propertyName = $propertyMatch.Value.Trim( @('{','}') )
    $propertyValue = $file.$propertyName
    $template = ($template -replace $propertyMatch.Value, $propertyValue)
Write-Host $template
$template | Out-File $destinationPath -Append
  • Define the template file that should be used 
  • Define the destination file that should be created / appended to
  • Match the regex against the content of the template file to find the required properties
  • Replace all the property names in the template file with their actual values
  • Write the result to the destination file


Using the template shown before the output should look similar to this:

 <table border="1">
   <td>Design Document</td>


  • This code snippet will always use the same destination file and append to it.