Reputation: 175
I've had a script that I've been using for a long time with PowerShell 5 accessing Outlook. It leverages this:
Add-type -assembly "Microsoft.Office.Interop.Outlook"
I can't seem to find an equivalent for PowerShell 7 (.NET Core). Anyone know what I can use in it's place? I have a script written in 7 that I would like to leverage Outlook for. Thanks
Upvotes: 1
Views: 1118
Reputation: 527
As I understand it, Add-Type
in PS7 can add only .NET Core assemblies by name alone, so you'll have to find a path to the file and use -LiteralPath
. You can start by looking in one of the following paths:
C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\
C:\Program Files (x86)\Microsoft Office\root\Office16\ADDINS\
You could look for the latest version with something like:
$SearchPath = 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook'
$SearchFilter = 'Microsoft.Office.Interop.Outlook.dll'
$PathToAssembly = Get-ChildItem -LiteralPath $SearchPath -Filter $SearchFilter -Recurse |
Select-Object -ExpandProperty FullName -Last 1
And add the assembly with:
if ($PathToAssembly) {
Add-Type -LiteralPath $PathToAssembly
}
else {
throw "Could not find '$SearchFilter'"
}
Upvotes: 2