Powershell export to excel

Handian Sudianto 6,621 Reputation points
2025-11-11T23:59:42.8366667+00:00

If we have Powershell script, can we export the result to xls file and not csv?

I try to use below command but not successful.

$Result | Export-Excel -Path $excelPath -AutoSize -BoldTopRow -FreezeTopRow -WorksheetName "Report1"

Windows for business | Windows 365 Enterprise
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-11-12T00:00:21.1333333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To export results from PowerShell to an Excel file, you can use the Export-Excel cmdlet, which is part of the ImportExcel module. This module allows you to create Excel files directly from PowerShell objects. If your command is not working, ensure that you have the ImportExcel module installed and imported into your PowerShell session. You can install it using the following command:

    Install-Module -Name ImportExcel
    

    After installing, make sure to import the module:

    Import-Module ImportExcel
    

    Then, you can use your command as follows:

    $Result | Export-Excel -Path $excelPath -AutoSize -BoldTopRow -FreezeTopRow -WorksheetName "Report1"
    

    If you are still facing issues, check for any errors in the command or ensure that $Result contains valid data to export. Also, verify that the path specified in $excelPath is correct and that you have permission to write to that location.

    0 comments No comments

  2. Harry Phan 10,695 Reputation points Independent Advisor
    2025-11-12T00:25:20.6433333+00:00

    Hello Handian Sudianto, the AI suggestion above is a good approach, however, if it doesn't work out, you might wanna try some other troubleshooting steps:

    First, make sure the module is up to date by running Update-Module ImportExcel. Also, check that the target Excel file isn’t open or locked—this can silently block the export. Running PowerShell as Administrator can help bypass permission issues, especially on corporate machines.

    To isolate the problem, try exporting a simple object like this:
    $Test = [PSCustomObject]@{Name="Test"; Value=123}

    $Test | Export-Excel -Path "$env:USERPROFILE\Desktop\Test.xlsx"

    If that works, the issue may be with the structure of your $Result data. Reinstalling the module (Uninstall-Module then Install-Module) can also help if something got corrupted.

    Let me know if this helps—and if it does, feel free to hit “Accept Answer” in the corner 😊

    Harry.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.