process word documents in Azure Powershell

0

User story: we migrated tons of word documents with links form our old SharePoint environment to SharePoint online. We would like to replace these links in all of these document to point the new place. This looks a simple job in PowerShell on my desktop, but I'd rather run the job as a PowerShell runbook in Azure.

Is this possible? The script is using the word application (other ideas are also welcome):

$Word = New-Object -ComObject Word.Application
$doc = $Word.Documents.Open($path)
$fc = $doc.Fields.Count

for ($i=1; $i -le $fc; $i++){
$field = $doc.Fields[$i]
$field.LinkFormat.SourceFullName
$newlink = $field.LinkFormat.SourceFullName -replace "A.docx","B.docx"

$field.LinkFormat.SourceFullName = $newlink
$field.Update()
}
$doc.Save()
$Word.Quit()

In Azure, the code fails at start, which looks logical as I need to load the word libraries somehow.

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

powershell
ms-word
office365
azure-powershell
asked on Stack Overflow Nov 8, 2019 by vilmarci

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0