PowerShell fails to launch excel with CLSID COM error

IT Magician 1 Reputation point
2021-12-28T20:03:40.91+00:00

Hi Community,

Really simple issue here we cannot figure out:

  1. Since 2015, Microsoft released this functionality and is officially documented here
  2. When we try to run the command in PowerShell below this is what happens:

$excel = New-Object -ComObject Excel.Application

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not

registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

  • CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
    • FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

Troubleshooting completed:

  1. Tested this on other computers. It is hit or miss, about 50% of the computers work and 50% give the error message below.
  2. Gave users local admin rights, same issue
  3. Reinstalled Microsoft Office, same issue
  4. Ran SFC/DISM, reinstalled .NET, same issue
  5. If we right click PowerShell and select RUN AS ADMIN, the command works without any errors!

At this point we are stumped. All computers are on latest Windows 10 patch and are basically standard setups (no fancy configurations). I opened a ticket with Microsoft and they said to come here because they do not support PowerShell being used this way.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,426 questions
{count} votes

4 answers

Sort by: Most helpful
  1. MotoX80 32,431 Reputation points
    2021-12-28T23:35:43.293+00:00

    If we right click PowerShell and select RUN AS ADMIN, the command works without any errors!

    You can avoid the "right click" by creating a bat file to launch Powershell. Your users will still get the UAC prompt, but it's a bit simpler.

    In the bat file, point this command to your script.

    powershell.exe Start-Process  powershell.exe  -ArgumentList "c:\Scripts\MyScript.ps1" -Verb runas
    

  2. IT Magician 1 Reputation point
    2021-12-31T16:22:55.5+00:00

    Additional steps I have performed:

    1. Installed developer for powershell 2022 and ran regasm.exe successfully for following two items: C:\Program Files\Microsoft Office\root\Office16\ADDINS\PowerPivot Excel Add-in\Microsoft.Office.Interop.Excel.dll and C:\Program Files\Microsoft Office\root\Office16\ADDINS\Microsoft Power Query for Excel Integrated\bin\Microsoft.Office.Interop.Excel.dll
    2. I confirmed in the registry and component explorer that Excel is listing the CLSID correctly as {00020812-0000-0000-C000-000000000046}, even though when powershell runs without admin it shows all zeros (and even more weird, when it runs as admin correctly shows {00020812-0000-0000-C000-000000000046})
    3. I installed .NET 3.5 (I know not related was just trying)
    4. I ran dependency walker and got this error when looking at the the Microsoft.Office.Interop.Excel.dll 161655-2021-12-31-09-56-23-jfdi-nv-001-teamviewer.png

    Does anyone know, when powershell is opened and $excel = New-Object -ComObject Excel.Application, what is the execution order?

    0 comments No comments

  3. IT Magician 1 Reputation point
    2021-12-31T16:48:35.207+00:00

    Hey Everyone,

    I isolated the issue and need help. We have folder redirection, and so running $excel = New-Object -ComObject Excel.Application fails with that error. Even if I login with our domain admin account, it still fails unless I right click powershell and run as admin.

    However, if I login to both a local admin or local non-admin user and run $excel = New-Object -ComObject Excel.Application, it works as intended!

    I found the Microsoft.Excel COM object and added domain users to have access, but it still fails. Anyone have any ideas here?

    Thank you


  4. My1 ‪ 0 Reputation points
    2024-03-14T12:32:08.99+00:00

    One thing that can help with this issue especially on systems with Folder Direction, AD and so on, is just nuking the user from that PC via advanced system settings, on the next login network will be needed but it will rebuild the user if set that way and it can help solve this issue.

    0 comments No comments