title: Delete folder older than 7 days
body: <pre><code>    #Script to delete or list old files in a process folder older than 7 days.
     # DESCRIPTION 
  #Script to delete files older than 7-days. The script is built to be used as a scheduled task,it automatically generates a logfile name based on the copy location and the current date/time. 
  #.NOTES   
  #Name: scmuploadlogsdeletes.ps1
  #Author: Kirubagari
  #Version:2.0
  #DateCreated: 2021-09-13
  
  
  
  $Path = Get-Content $dir\path.txt
  
  
  $date = get-date -Format D
  
  
  
  &lt;# This sets the path and file name for the log file that will be exported at the end of the script #&gt;
  $logfilepath = $Path +&quot;\&quot; + $date + &quot; Deletion Log.txt&quot; 
  
  &lt;# This sets the title at the top of the log file #&gt;
  $logfile = &quot;Log for: &quot; + $date + &quot;`n`n&quot;
  
  Write-Host &quot;Script is working on &quot; $Path 
  #Delete files older than 14 days
  Get-ChildItem $Path  -Recurse -Force -ea 0 |
  ? {!$_.PsIsContainer -and $_.LastWriteTime -lt (Get-Date).AddDays(-50)} |
  ForEach-Object {
     $_ | del -Force
       
     Write-Host &quot;Script has deleting $_&quot;;
     $_.FullName | Out-File $logfilepath -Append
     
  }
  
  
  
  #Delete empty folders and subfolders
  Get-ChildItem $Path  -Recurse -Force -ea 0 |
  ? {$_.PsIsContainer -eq $True} |
  ? {$_.getfiles().count -eq 0} |
  ForEach-Object {
      $_ | del -Force
      
      Write-Host &quot;Script has deleting $_&quot;;
      $_.FullName | Out-File $logfilepath -Append
      }
  
  $logfile | out-file $logfilepath  
  Write-Host &quot;Script has finished the task&quot;;
  </code></pre>
  <p>My script as above where im planning to delete folder than 7 days but its taking so much time to delete. Do i required to delete files inside the folder first and then files? The above code will delete all the files first and proceed with folder? Any other script i can use instead PowerShell?</p>