title: Check if a Zip file is password protected
body: <p>I am using PowerShell to extract multiple ZIP files. Some of these files are password protected. The requirement is to skip the files that are password protected. When this code encounters a password protected file, it displays a box to enter the password. Is there any way to check if the ZIP file is password protected before I extract it? I tried <a href="http://dotnetzip.codeplex.com/" rel="nofollow">DotNetZip</a> too, but was not able to find a way to determine if the file is password protected.</p>
  
  
  
  <pre class="lang-psh prettyprint-override"><code>$shell = new-object -com shell.application
  $zip = $shell.NameSpace("C:\ZipFile.zip")
  foreach ($item in $zip.items()) {
    $shell.Namespace("C:\ExtractedFiles").copyhere($item)
  }
  </code></pre>
  
  <p>Update:</p>
  
  <p>I am able to detect encrypted files using DotNetZip. It would be better if I can do this without DotNetZip.</p>
  
  <pre class="lang-psh prettyprint-override"><code>[System.Reflection.Assembly]::LoadFrom("C:\Ionic.Zip.dll") 
  $zipfile = [Ionic.Zip.ZipFile]::Read($file.FullName) 
  $encFlag = $false
  foreach ($file in $zipfile) {
    if ($file.UsesEncryption -eq $true) {
      $encFlag = $True
    }
  }
  Write-Host "Enctryption: " $encFlag
  </code></pre>