powershellsecurity

Powershell to find all files in a folder NOT password-protected ZIP and delete them


I found this one - > https://superuser.com/questions/1150631/powershell-script-to-test-zip-passwords-from-file - > but it looks like what I need is a little different.

Is it possible to find all files in a folder which are NOT protected by a password and delete them?

Trying to solve the problem of people putting all kinds of sensitive files where these files shouldn't be.


Solution

  • You can try the following:

    Get-ChildItem -Filter *.zip |
      Where-Object { '' | 7z t $_.FullName *>$null; $LASTEXITCODE -eq 0 } |
      Remove-Item -WhatIf
    

    Note: The -WhatIf common parameter in the command above previews the operation. Remove -WhatIf once you're sure the operation will do what you want.