Ditto to what Olaf has stated.
So, if you have not looked at the available data points on PowerShell when using Excel to come up with code that you may need help with, a quick web search would point you to such help, to get you started. For example.
Introducing the PowerShell Excel Module
The PowerShell Excel Module is a brand new, exciting, and better way to interact with Microsoft Excel from Windows PowerShell. Plus for bonus points, you don’t need Excel installed on the target machine to create the spreadsheet. Many users of this module generate Excel spreadsheets on servers, and then others in the company pick up the reports from a central server. Or for the last step in their script, they can mail the .xlsx file.
Creating a spreadsheet
Creating an Excel spreadsheet should be a simple act, in theory. But if you don’t happen to be in the U.S., there’s a slight issue in the shape of a bug in versions of Excel 2007 and earlier that can prevent this from working. After reading this, it won’t matter where you live. If you’re using Excel 2010, the first version in Listing 1 can be used wherever you live and work.
We need to create an Excel spreadsheet from within a Windows PowerShell script.
The Excel.application COM object can be used to create a spreadsheet.
PowerShell: Generate Real Excel XLSX Files without Excel
I had the need to store data into a Microsoft Excel compatible file.
Attempt 1: Use the Excel COM object model.
This is not a good solution because:
PowerShell runs very often on Servers or clients without a Microsoft Office / Excel installation.
The use of the Excel COM Object can cause errors inside a Scheduled Task.
Excel can read and store CSV data.
Attempt 2: Use CSV data (with Export-CSV)
This is not a good solution either because:
CSV is not just another type of Excel file. On opening a CSV data file, Microsoft Excel converts data automatically. This is not acceptable.
If Microsoft Excel outputs an Excel worksheet into a CSV file, the output does not always follow the CSV format rules. Excel only places quotes around certain fields not on all fields. This leads to unreadable CSV files.