The script also dumps a log file using the Start-Transcript/Stop-Transcript command pair.
All PCs are configured to be in Constrained Language mode as per the transcript output:
Language mode: ConstrainedLanguage
On most PCs (>100) the script executes without issues but on some (<10) I get the following error when executing the New-Object command:
PS>TerminatingError(New-Object): "Cannot create type. Only core types are supported in this language mode."
I have verified that all PCs are running the same versions of Windows (Microsoft Windows NT 10.0.19044.0), PowerShell (5.1.19041.2673) etc by comparing the transcript output.
Can anyone suggest a reason why I would be seeing this error?
Constrained Language consists of a number of restrictions that limit unconstrained code execution on a locked-down system. These restrictions are:
PowerShell module script files must explicitly export functions by name without the use of wildcard characters. This is to prevent inadvertently exposing powerful helper function not meant to be used publicly.
PowerShell module manifest files must explicitly export functions by name without the use of wildcards. Again, to prevent inadvertent exposure of functions.
COM objects are blocked. They can expose Win32 APIs that have likely never been rigorously hardened as part of an attack surface.
It actually works on my PC which is in Constrained mode. ie: I don’t get an error when using the New-Object command.
I do however, get an error when running the New-Object command on a PC which is normally in FullLanguage mode that has been placed in Constrained mode using the command: