zip-module.psm1 945 B

12345678910111213141516171819202122232425262728293031323334
  1. Function Expand-ZipFile {
  2. Param(
  3. [Parameter(Mandatory = $true)] [string] $zipfile,
  4. [Parameter(Mandatory = $true)] [string] $destination
  5. )
  6. # This function unzips a zip file
  7. # Code obtained from:
  8. # http://www.howtogeek.com/tips/how-to-extract-zip-files-using-powershell/
  9. Begin { Write-Host " - Unzipping '$zipfile' to '$destination'" }
  10. Process {
  11. # Create a new directory if it doesn't exist
  12. If (!(Test-Path -Path $destination))
  13. {
  14. New-Item -ItemType directory -Path $destination
  15. }
  16. # Define Objects
  17. $objShell = New-Object -Com Shell.Application
  18. # Open the zip file
  19. $objZip = $objShell.NameSpace($zipfile)
  20. # Unzip each item in the zip file
  21. ForEach ($item in $objZip.Items())
  22. {
  23. $objShell.Namespace($destination).CopyHere($item, 0x14)
  24. }
  25. }
  26. End { Write-Host " - Finished"}
  27. }