Forum Discussion

AtanasM's avatar
AtanasM
Iron Contributor
Nov 03, 2022

Script to delete automatically all incoming files in a folder.

Employee receives daily orders in excel files. If he completes the order, the file is moved to the folder "Completed  orders". A PowerShell script is needed to delete automatically the files in  the ...
  • Alan2022's avatar
    Alan2022
    Nov 20, 2022

    AtanasM 

     

    Hi,

    This script will delete all excel in Completed  orders.
    Note the remove item is being remarked.
    Also removing -recurse parameter will not check sub folders.

     

     

    Clear-Host
    
    # Extract List of XLSX Files
    $xlsxLocation = "C:\Completed  orders\*.xlsx"
    $xlsxFiles = Get-ChildItem -Path $xlsxLocation -Force | Sort-Object LastWriteTime
    
    # List every XLSX Files
    foreach($xlsxFile in $xlsxFiles){
        
        Write-Host $xlsxFile.Fullname 
        # Remove-Item -Path $xlsxFile.Fullname 
        
    }

     

     

Resources