New-WordInstance
New-WordDocument
Add-WordText -text "Lorem Ipsum" -WDBuiltinStyle wdStyleHeading1
Add-WordText -text "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc volutpat non lorem non viverra." -WDBuiltinStyle wdStyleNormal
Save-WordDocument -Filename "test.docx" -Folder "D:\temp\"
Word opens and the content is added to the new document, but the Save-WordDocument cmdlet fails:
PS> .\test.ps1
WARNING: *** MS Word may be behind this window! ***
WARNING: Save-WordDocument - Exception setting "SaveAs": Cannot convert the "D:\temp\test.docx" value of type "psobject" to type "Object".
I expect to be able to create and save the file directly from the powershell script (I need to create a bunch of about a thousand files for testing purposes).
Can you please clarify what I'm doing wrong?
Thanks a lot,
Massimo
PS
I'm running windows 10 Pro 64 bit, Version 1709.
D:\temp\ is an empty, writeable folder on my PC.
PS> Get-InstalledModule WordDoc
Version Name Repository Description
------- ---- ---------- -----------
1.2.1 WordDoc PSGallery Generate Word Documents directly from PowerShell..
PS> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.16299.251
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.251
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1