# You can use DotNetZip from Powershell

The programming model is the same as for VB or C#, with a few syntactic changes for Powershell. This page will show some examples.

### Create a zip file

This example just creates a simple zipfile

    # Load the assembly - replace this with your own path
    [System.Reflection.Assembly]::LoadFrom("c:\\dinoch\\bin\\Ionic.Zip.dll");

    $directoryToZip = "c:\\temp";
    $zipfile =  new-object Ionic.Zip.ZipFile;
    $e= $zipfile.AddEntry("Readme.txt", "This is a zipfile created from within powershell.")
    $e= $zipfile.AddDirectory($directoryToZip, "home")
    $zipfile.Save("ZipFiles.ps1.out.zip");
    $zipfile.Dispose();

### Create a zip file using AES encryption

This example creates a zipfile, using AES 256-bit encryption to encrypt the entries.

    # Load the assembly - replace this with your own path
    [System.Reflection.Assembly]::LoadFrom("c:\\dinoch\\bin\\Ionic.Zip.dll")

    $directoryToZip = "c:\\dinoch\\dev\\powershell"
    $zipfile =  new-object Ionic.Zip.ZipFile
    $zipfile.Encryption = [Ionic.Zip.EncryptionAlgorithm]::WinZipAes256
    $zipfile.Password = "Albatros$"
    $e= $zipfile.AddEntry("Readme.txt", "This is a zipfile created from within powershell.")
    $e= $zipfile.AddSelectedFiles("name != *.zip", $directoryToZip, "home")
    $zipfile.Save("ZipFiles.ps1.out.zip")
    $zipfile.Dispose()

### Create a number of zip files, each containing a single file

This example iterates through a set of files, and creates a zipfile containing a single file, for each one.

    # Load the assembly - replace this with your own path
    [System.Reflection.Assembly]::LoadFrom("c:\\dinoch\\bin\\Ionic.Zip.dll");

    foreach ($file in gci $LogPath -filter $FileType -recurse |
            where{$_.LastWriteTime -lt [DateTime]::Now.AddDays($DaysOld)})
    {
        $FileName = $File.FullName
        $ZipName = $File.FullName + ".zip"
        $zip = new-object Ionic.Zip.ZipFile
        $zip.AddFile($FileName, "");
        $zip.Save($ZipName)
        $zip.Dispose()
    }