Powershell script that removes files from cvs list and then exports results

This topic contains 1 reply, has 2 voices, and was last updated by  Matt Bloomfield 6 months ago.

  • Author
    Posts
  • #71137

    josh
    Participant

    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
    }
  • #71143

    Matt Bloomfield
    Participant

    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

You must be logged in to reply to this topic.