Could anyone explain to me why, upon running this script I get the following error: [
Unable to find type]?
A using namespace statement is merely a syntactic convenience: it allows you to reference already loaded types by their simple name, without having to use the namespace part (in the case at hand, [Application] instead of [Microsoft.Office.Interop.Word.Application])
Thus, you must ensure separately that the assemblies containing the types of interest are loaded, either via using assembly statements or Add-Type calls.
Therefore:
# NOTE:
# Windows PowerShell only - doesn't work in PowerShell (Core) 7, as of v7.4.x
using assembly Microsoft.Office.Interop.Word
using namespace Microsoft.Office.Interop.Word
using namespace System.Management.Automation
$ErrorActionPreference = [ActionPreference]::Stop
[Application]$wordApp = new-object -comobject Word.Application
$wordApp.Name # Get and output the .Name property value, for demonstration purposes.
$wordApp.Quit()