Author Posts

May 21, 2017 at 12:31 am

How do I export the results into an Excel spreadsheet and highlight them in green once the files have been deleted from a csv list in Powershell? I have a powershell script that removes files from a csv list. However, I'm not sure how to export the results once the files have been deleted from the list and mark them in green in a spreadsheet in Excel. How would I approach this? Below is my powershell script:

$files = Get-Content "C:\test\remove.csv"
foreach ($file in $files) {
Remove-Item -Path $file -force
}

May 21, 2017 at 12:15 pm

Doug Finke's ImportExcel module requires a bit of work to learn but is very powerful.

Here's a simple example:

$files = 'file1.exe','file2.txt','file3.pdf'

$files | Export-Excel deletedFiles.xlsx -CellStyleSB { 
         
    param( 
             $workSheet, 
             $totalRows, 
             $lastColumn 
         ) 
                  
    foreach ($row in 2..$totalRows) {Set-CellStyle $workSheet $row $lastColumn Solid Green}

}

https://github.com/dfinke/ImportExcel