COM Objects, Powershell 5 vs 7 and Constrained Language mode

148 Views Asked by At

I have a strange issue and wonder if anyone has any ideas. I am trying to make a powershell script that can replace text in a word document.

This script works fine on version 5 but not on version 7

How to use Powershell to replace text in Word which is in single line and different line?

The problem is the command

New-Object -ComObject word.application

In version 5 it works, but in version 7 I get

New-Object: Cannot create type. Only core types are supported in this language mode.

In both shells I get that the languagemode is Constrained.

PS C:\Windows\System32> $ExecutionContext.SessionState.LanguageMode

ConstrainedLanguage

Any ideas?

0

There are 0 best solutions below