excel creation with powershell


I try to create a excel file in a powershell script using this code :

$xl = New-Object -ComObject "Excel.Application"
$xl.Visible = $false
$xl.DisplayAlerts = $false
$wb = $xl.Workbooks.Open($scriptPath + "\..\..\NeededTools\ExploitationApplication.xlsm")
$global:ws = $wb.sheets.Item(3)

And I face this exception :

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)).

Do someone have informations about this exception or a sample used to generate a excel file correctly ? Is it possible to have this error because I dont have excel on this server ?

asked on Stack Overflow Jul 28, 2015 by Xavier W.

3 Answers


You do not have Excel installed. Or you have, and need to run repair.

answered on Stack Overflow Jul 28, 2015 by (unknown user) • edited Apr 24, 2020 by Community

I had the same problem in my Desktop from a C# application after a Windows/Office update from my company IT (Office16). It worked for 5 years without any problems.

I create a Powershell script that launch excel to update a table that works well in my Laptop but still not in my Desktop.

After long search and follow the indication from this link (https://social.technet.microsoft.com/Forums/lync/en-US/05a1635d-142c-4866-8455-1341280967fd/windows-explorer-preview-of-office-2016-files-does-not-work?forum=Office2016setupdeploy).

I found that some information was missing in the Windows registry.

In details: comparing the Registry key "Computer\HKEY_CLASSES_ROOT\WOW6432Node\CLSID{00024500-0000-0000-C000-000000000046}" from my Laptop, in my Desktop I had only one key, "InprocServer32" instead of 5 keys.

I added the following key folders and values under "Computer\HKEY_CLASSES_ROOT\WOW6432Node\CLSID{00024500-0000-0000-C000-000000000046}":

"LocalServer32" => default: "C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL.EXE /automation"
"ProgID" => default: "Excel.Application.16"
"VersionIndependentProgID" => default: "Excel.Application"
"InprocHandler32" => default: "ole32.dll"

Note: the "LocalServer32" was enough to run the script

Registry key structure

answered on Stack Overflow Apr 20, 2021 by Massimo P.

You do not have Excel installed. Or you have, and have to repair it.

answered on Stack Overflow Apr 24, 2020 by springfeld

User contributions licensed under CC BY-SA 3.0