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.