Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. Param(
  2. [string]$pathToPackages
  3. )
  4.  
  5. Add-Type -AssemblyName System.IO.Compression.FileSystem
  6. function Unzip
  7. {
  8. param([string]$zipfile, [string]$outpath)
  9.  
  10. [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
  11. }
  12. function ZipDirectory
  13. {
  14. param([string]$zipfilename, [string]$sourcedir)
  15.  
  16. $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
  17. [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, $compressionLevel, $false)
  18. }
  19. function RemoveBinFiles
  20. {
  21. param([string]$path, [string]$updateFile)
  22.  
  23. $packageNameOnly = "$($path)\$($updateFile)"
  24. $package = "$($packageNameOnly).update"
  25. $packageDirectory = "$($path)\package"
  26. $packageZip = "$($packageDirectory).zip"
  27. $packageBin = "$($packageDirectory)\addedFiles\bin"
  28. $packagePropertiesBin = "$($packageDirectory)\properties\addedFiles\bin"
  29.  
  30. Unzip $package $path
  31.  
  32. if (Test-Path $packageDirectory) {
  33. Remove-Item $packageDirectory -recurse
  34. }
  35.  
  36. Unzip $packageZip $packageDirectory
  37.  
  38. Remove-Item $packageZip
  39.  
  40. if (Test-Path $packageBin) {
  41. Remove-Item $packageBin -recurse
  42. }
  43.  
  44. if (Test-Path $packagePropertiesBin) {
  45. Remove-Item $packagePropertiesBin -recurse
  46. }
  47.  
  48. ZipDirectory $packageZip $packageDirectory
  49.  
  50. if (Test-Path $packageDirectory) {
  51. Remove-Item $packageDirectory -recurse
  52. }
  53.  
  54. if (Test-Path $package) {
  55. Remove-Item $package
  56. }
  57.  
  58. New-Item -ItemType directory -Path $packageNameOnly
  59.  
  60. Move-Item -Path $packageZip -Destination $packageNameOnly
  61.  
  62. ZipDirectory $package $packageNameOnly
  63.  
  64. if (Test-Path $packageNameOnly) {
  65. Remove-Item $packageNameOnly -recurse
  66. }
  67. }
  68.  
  69. Get-ChildItem $pathToPackages -Filter *.update |
  70. Foreach-Object {
  71. $packageName = $_.BaseName
  72. Write-Host $packageName
  73. RemoveBinFiles $pathToPackages $packageName
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement