I have a script that duplicates a Word doc template and renames each using a csv file with a list of names. What would be the equivalent code if instead of a csv file I use a text file?

Import-csv ‘.\individuals2.csv’ | foreach-object {
	$newname = ‘2 ‘ + $_.name + '.docx’
	Copy-item '.\template.docx' $newname
}

It’s markdown, you should be able to indent your lines by 4 spaces or fence with triple backtics to get code blocks. Your client’s editor may have a button to help

```
$file = Get-Content -Path .\individuals2.txt

foreach ($line in $file)
{
    Copy-Item -Path .\template.docx -Destination ".\$(2 + $line + '.docs')"
}
```

Becomes

$file = Get-Content -Path .\individuals2.txt

foreach ($line in $file)
{
    Copy-Item -Path .\template.docx -Destination ".\$(2 + $line + '.docs')"
}

That’s good to know. Thanks!

Create a post

All things programming and coding related. Subcommunity of Technology.


This community’s icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

  • 1 user online
  • 2 users / day
  • 2 users / week
  • 8 users / month
  • 98 users / 6 months
  • 1 subscriber
  • 302 Posts
  • 2.15K Comments
  • Modlog