Nice DOTNETZIP Integration with PowerShell

Let me share a script I built two years ago, and I just created a function for it named “New-ZipFile“. Basically, this PowerShell function script will create a blank zipped file and copy the files to it. At the same time if you run it again (after updating an existing file) will overwrite the file any existing files previously on the existing zipfile. Also, there’s no prompt.

This is an example of what PowerShell can provide at an excellent tool for providing creative solutions. Also the community is very active is helping everyone.

I agree that sometime is not easy but definitely not impossible. And there’s lots of other possible good alternative. But, using PowerShell let you customized your solution with an opportunity for enhancements giving you some level of control over what you want to accomplish.

I’m using the DOTNETZIP from Codeplex for this example. By the way, they provide good documentation on how to use the API’s. (hint: copy all the “Tools” folder to “Program Files (x86)\DotNetZip\..” folder)

You can download DOTNETZIP at the following link: http://dotnetzip.codeplex.com/

Here’s the sample script. Just change the variables values to your need, and make it your own:

[sourcecode language=”powershell”]
## – Beginning of Script:
Function New-ZipFile{
PARAM
(
[String] $SrcFolder,
[String] $DestFolder,
[string] $DestZipName,
[String] $FileExtToZip,
[string] $ZipPurpose,
[string] $StoredInZipFolder,
[string] $DeleteFiles = $null
)
#$TodaysDate = Get-Date -uformat "%Y-%m-%d-%Hh%Mm%Ss.zip";
#$ZipFileName = $ZipPurpose + "_" +$DestZipName + "_" + $TodaysDate;
$ZipFileName = $ZipPurpose + "_" +$DestZipName + ".zip";

if (Test-Path $DestFolder){
## – Create Zip file or it won’t work:
if (Test-Path ($DestFolder+"\"+$ZipFileName)) { del ($DestFolder+"\"+$ZipFileName) }
new-item ($DestFolder+"\"+$ZipFileName) -ItemType File
}
else
{
Write-Host "Destination Folder [$DestFolder] doesn’t exist" -ForegroundColor ‘Yellow’;
Break;
};

## – Loads the Ionic.Zip assembly:
[System.Reflection.Assembly]::LoadFrom("C:\Program Files (x86)\DotNetZip\Ionic.Zip.dll") |

out-null;
$zipfile = new-object Ionic.Zip.ZipFile

## – AddSelectedFiles with source folder path:
## – ($false grab files in source folder) & ($true grab files & subfolder files)
$zipfile.AddSelectedfiles($FileExtToZip,$SrcFolder,$true) | Out-Null;
## – UseZip64WhenSaving, when needed, will create a temp file compress large number of files:
$Zipfile.UseZip64WhenSaving = ‘AsNecessary’
$zipfile.Save($DestFolder+"\"+$ZipFileName)
$zipfile.Dispose()

If ($DeleteFiles.ToUpper() -eq ‘YES’){
## – Remove all backed up files:
Write-Host "Deleting files after zip!";
get-childitem ($SrcFolder+"\"+$FileExtToZip) | remove-item
}
};

### – variables:
$DestZipName = "BackupMyTempSSIS";
$FileExtToZip = "name = *.*";
$DestFolder = "C:\MyBackupZipFolder";
$SrcFolder = "C:\TempSSIS";
$DeleteFiles = $null;
$StoredInZipFolder = "MyBackupZip\";
$ZipPurpose = "BackUp";
#or $ZipPurpose = "Save";

New-ZipFile -DeleteFiles $DeleteFiles `
-DestFolder $DestFolder -DestZipName $DestZipName `
-FileExtToZip $FileExtToZip -SrcFolder $SrcFolder `
-StoredInZipFolder $StoredInZipFolder -ZipPurpose $ZipPurpose;

## – End of Script
[/sourcecode]

This is about having flexibility over what you want to do.  This is a good example how you can use an existing API with PowerShell.  As long there’s good API documentation then the rest just follows thru.

DotNETzip_APIDoc

In the above sample script you can have is Scheduled in either Task Scheduler or in SQL Server Agent. This code becomes portable.

This script the folder for the zipped file most exist or it will display a message that the folder doesn’t exist, and has the ability to delete the files after its done. (feel free to modify)

I hope you’ll find it useful!

Maximo Trinidad (MVP – Windows PowerShell)
Mr. PowerShell

102 thoughts on “Nice DOTNETZIP Integration with PowerShell

  1. Pingback: slcshop.top
  2. Pingback: upmusic.icu
  3. Pingback: we-b-tv.com
  4. Pingback: hs;br
  5. Pingback: tureckie_serialy_na_russkom_jazyke
  6. Pingback: tureckie_serialy
  7. Pingback: 2020
  8. Pingback: kpop+star+season+6+ep+9
  9. Pingback: Video
  10. Pingback: +1+
  11. Pingback: 1 2 3 4 5 6 7 8 9 10
  12. Pingback: wwin-tv.com
  13. Pingback: pornvideo
  14. Pingback: buy cialis
  15. Pingback: cheap viagra
  16. Pingback: buy sildenafil
  17. Pingback: buy cialis
  18. Pingback: buy viagra online
  19. Pingback: ou trouver viagra sans ordonnance
  20. Pingback: buy viagra
  21. Pingback: cheap ed pills
  22. Pingback: Cheap Erection Pills
  23. Pingback: cialis online
  24. Pingback: generic cialis buy
  25. Pingback: buy cialis overnight
  26. Pingback: cialis online
  27. Pingback: generic cialis buy
  28. Pingback: buy cialis overnight
  29. Pingback: buy cialis
  30. Pingback: cialis miami
  31. Pingback: buy amoxicillin
  32. Pingback: 5mg cialis
  33. Pingback: payday loans online fast deposit
  34. Pingback: buy levitra in australia
  35. Pingback: the best custom essay writing service
  36. Pingback: personal loans
  37. Pingback: cheap cialis online pharmacy
  38. Pingback: buy viagra sydney
  39. Pingback: ed drugs cialis
  40. Pingback: cialis ordering australia
  41. Pingback: Testing60
  42. Pingback: Testing61
  43. Pingback: cialis 20mg for sale
  44. Pingback: buy cialis online europe
  45. Pingback: cheapest generic cialis australia
  46. Pingback: where can i buy cialis without a prescription
  47. Pingback: cialis 20mg low price
  48. Pingback: cialis 20mg for sale
  49. Pingback: buy cialis cheaper online
  50. Pingback: cialis 20 mg cost
  51. Pingback: where can i buy cialis without a prescription
  52. Pingback: buy cialis 36 hour
  53. Pingback: axvgcqus
  54. Pingback: buy cialis online generic
  55. Pingback: where to buy cheap viagra online
  56. Pingback: hoe vaak viagra
  57. Pingback: what is the azithromycin combination
  58. Pingback: cialis sale 20mg
  59. Pingback: generic cialis 20 mg tadalafil
  60. Pingback: cialis
  61. Pingback: viagra from canada
  62. Pingback: buy cialis without perscription
  63. Pingback: cialis 20mg low price
  64. Pingback: viagra sin receta espaГ±a
  65. Pingback: buy cialis toronto
  66. Pingback: order original cialis online
  67. Pingback: uk custom essay writing service
  68. Pingback: online research paper writer
  69. Pingback: who can write my essay
  70. Pingback: generic cialis 20 mg tadalafil
  71. Pingback: help with essay writing
  72. Pingback: find cheap cialis online
  73. Pingback: buy cialis canadian
  74. Pingback: generic cialis 20 mg tadalafil
  75. Pingback: generic cialis 20 mg tadalafil
  76. Pingback: amoxicillin 800 mg
  77. Pingback: furosemide 40mg tab without prescription
  78. Pingback: azithromycin in usa
  79. Pingback: stromectol buy
  80. Pingback: buy combivent from canada
  81. Pingback: Google
  82. Pingback: doxycycline vibramycin
  83. Pingback: prednisolone 20 mg
  84. Pingback: clomid only cycle
  85. Pingback: dapoxetine india price
  86. Pingback: diflucan pill
  87. Pingback: zoloft and synthroid
  88. Pingback: propecia 1mg online
  89. Pingback: how much neurontin
  90. Pingback: diabetes drugs metformin
  91. Pingback: paxil vs.xanax
  92. Pingback: plaquenil en espaГ±ol
  93. Pingback: buy cheap metformin
  94. Pingback: buy cialis online in canada
  95. Pingback: cialis tadalafil portugal
  96. Pingback: Zakhar Berkut hd
  97. Pingback: buy cialis insurance
  98. Pingback: payday loan yes irving
  99. Pingback: retin a cream online hong kong
  100. Pingback: cash advance usa baytown
  101. Pingback: buy canadian
  102. Pingback: where can i buy ativan in canada

Leave a Reply