I have a script used to create new projects. Within it, I create an Excel object subsequently used by the New-PWRichProjectsFromSpreadsheet cmdlet. It's worked with no issue until recently when the New-Object -ComObject excel.application started throwing this error:
New-Object : Creating an instance of the COM component with CLSID {00024500-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80010108 The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)).
What's odd is that if I attempt to run the line manually a second time it will succeed and create the object. PS is running as admin.
Any ideas why it may be failing?
FWIW, I have also tried a delay:
$Excel = $Null$excel = New-Object -ComObject excel.applicationStart-Sleep -Seconds 3
But even when I run this repeatedly it seems to fail inconsistently, for example 2 out of 5 times.
I find it very odd.
Jeff
Have you looked at the New-XLSXWorkbook cmdlet? May be a good alternative for you. It does not require Excel to be installed on the computer running PowerShell.