Log all deleted files

Welcome Forums General PowerShell Q&A Log all deleted files

Viewing 4 reply threads
  • Author
    Posts
    • #241361
      Participant
      Topics: 16
      Replies: 58
      Points: 62
      Rank: Member

      Hi ,

      Need help, i cleaning computer and want to log all files that was deleted

      This is what i do

      Get-ChildItem "C:\Windows\SoftwareDistribution\*" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
      Get-ChildItem "C:\Windows\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
      Get-ChildItem "C:\Windows\prefetch\*" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
      Get-ChildItem "C:\Users\*\AppData\Local\Temp" -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
      Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
      Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\INetCookies\*" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
      Get-ChildItem "C:\swsetup" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
      Get-ChildItem 'C:\Users\*\AppData\Local\CrashDumps\*' | remove-item -Force -recurse -ErrorAction SilentlyContinue
      Get-ChildItem 'C:\Users\*\AppData\Local\Microsoft\Windows\WER*' | remove-item -Force -recurse -ErrorAction SilentlyContinue

      Thanks.

    • #241391
      Participant
      Topics: 4
      Replies: 481
      Points: 1,760
      Helping Hand
      Rank: Community Hero
      $dirs = @(
          "C:\Windows\SoftwareDistribution\*",
          "C:\Windows\Temp\*",
          "C:\Windows\prefetch\*",
          "C:\Users\*\AppData\Local\Temp",
          "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files",
          "C:\Users\*\AppData\Local\Microsoft\Windows\INetCookies\*",
          "C:\swsetup",
          'C:\Users\*\AppData\Local\CrashDumps\*',
          'C:\Users\*\AppData\Local\Microsoft\Windows\WER*'
      )
      
      $log = "c:\temp\deleted_files.log"
      
      $dirs | foreach {
          "-" * 60
          ""
          "Items deleted from directory $_"
          Get-ChildItem $_ -OutVariable df | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue | Out-Null
          ""
          $df.name
          "" * 2
      } | out-file $log -Encoding ascii -Append
      
    • #241661
      Participant
      Topics: 16
      Replies: 58
      Points: 62
      Rank: Member

      Thank you Doug

    • #241769
      Participant
      Topics: 4
      Replies: 481
      Points: 1,760
      Helping Hand
      Rank: Community Hero

      You’re welcome. That do all you needed?

    • #242153
      Participant
      Topics: 16
      Replies: 58
      Points: 62
      Rank: Member

      Yes, Thank you Doug

Viewing 4 reply threads
  • You must be logged in to reply to this topic.