Excel.Application not found using SSM but works fine locally

0

When we execute below command using AWS-RunPowerShellScript, it fails. However, if same command is run locally, it runs successfully.

Command: $objExcel = New-Object -ComObject Excel.Application

Error on SSM: Error: CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException

  • FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
bokia
asked 9 months ago228 views
1 Answer
0

The error you're seeing indicates that the COM object Excel.Application can't be found. This usually happens when Microsoft Excel is not installed on the system where the script is running, or if the script does not have the appropriate permissions to access it.

When you're running this script locally, it has access to your local installation of Excel. But when you're running it on AWS SSM (Systems Manager), it's likely running on a remote instance where Excel isn't installed.

Here are a few things you could do to solve this issue: - Install Excel on the remote instance: If your licensing allows it, you could install Excel on the remote instance where the script is being executed. However, this might not be a good solution, especially if you're executing this script on multiple instances. - Use a different method to manipulate Excel files: COM objects rely on having Excel installed, but there are many libraries that can create, read, and write Excel files without needing Excel itself. For example, in PowerShell you could use the ImportExcel module, which doesn't require Excel to be installed. - Use AWS Lambda with .NET: AWS Lambda now supports PowerShell, so you might be able to refactor your code to run in a Lambda function instead of using SSM. This would still require you to not rely on Excel's COM object but could provide a more scalable solution. - Use Excel on an EC2 instance: An alternative solution would be to create a Windows EC2 instance, install Excel there and run your scripts on this instance instead. Note that you should have a valid license for installing Excel on EC2 instance.

In general, it's recommended to not rely on COM objects for server-side operations because they require an interactive user session and they're not designed for unattended execution. If you're performing operations on Excel files, there are many libraries available that can handle these operations without needing Excel to be installed.

profile picture
answered 9 months ago
  • Thanks for your response. So basically, let me rephrase the question. The script works fine locally. However, the script fails on the same EC2 instance (where excel is installed), when executed using SSM.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions