4

I am trying to load an Excel file using PowerShell Core for Mac but I am encountering an issue with New-Object. It's failing on the very first line

$Excel = New-Object -ComObject Excel.Application

This is the error message I receive:

New-Object : A parameter cannot be found that matches parameter name
'ComObject'.
At line:1 char:21
+ $Excel = New-Object -ComObject Excel.Application
+                     ~~~~~~~~~~
     + CategoryInfo          : InvalidArgument: (:) [New-Object], ParameterBindingException
     + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

Has anyone encountered this issue and does anyone know how to fix it?

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
kevin02
  • 41
  • 2
  • 4
    The `Excel.Application` COM object is only available when Excel is installed. And I'm not sure if the Mac version of MS Office even provides COM objects. You may want to consider using the [`ImportExcel`](https://www.powershellgallery.com/packages/ImportExcel) PowerShell module instead. – Ansgar Wiechers Aug 10 '18 at 13:41
  • 1
    There is not ComObject in Mac OSX even when Excel for Mac is installed. – corretge May 07 '19 at 15:56

1 Answers1

4

The error message you're receiving says the -ComObject parameter is invalid. Judging from this issue posted on the powershell github I'd say -ComObject is invalid because it is not supported on the Mac platform.

veefu
  • 2,820
  • 1
  • 19
  • 29