Update Word document to a new document template by using PowerShell

Organisations usually have tons of Word documents made by using a template. If this template is later changed, you need to update all existing documents somehow. I faced this issue when migrating from SharePoint onprem to SharePoint Online, and the document template was using SharePoint Column data in document headers. All the document headers were