locked
Fill templated word file with powershell RRS feed

  • Question

  • Hi,

    I have a word template file to print sticker (for moving our office)

    And I would like to have a way to fill it with powershell like this:

    #
    # Script.ps1
    #


    $ArrComputer = (Get-ADComputer -Filter "Name -like 'T430-*'" -SearchBase "OU=Computers,OU=Canada Office,DC=playtika,DC=local").Name


    Foreach ($Computer in $ArrComputer)

    {
       $file1 = "...\AveryLabelTemplate.doc"
       $word = New-Object -ComObject Word.Application
       $doc = $word.Documents.Add($file1)
       $selection = $doc.Selection
       $selection.typeText($Computer) -Append(or something like that)
    }

    $doc.visible = $True

    Someone know how??

    • Moved by jrv Wednesday, October 18, 2017 1:08 AM
    Tuesday, October 17, 2017 9:09 PM

All replies

  • Actually I don't know how to accomplish what you ask for the way you ask for and actually I don't see a question in your post but I could imagine that it's way more easy to create a csv file with Powershell and use it for Word for a mail merge document.

    Best regards (79,108,97,102|%{[char]$_})-join''

    Wednesday, October 18, 2017 12:13 AM
  • The MS Word user forum will tell you how to use a CSV to design and print labels.    The Avery forum and docs also show you how to do this.  It is not really a scripting issue.

    I am going to move this to the Word forum.


    \_(ツ)_/

    Wednesday, October 18, 2017 1:08 AM