Update-ZipEntry

Synopsis

Updates a &;39;.ZIP&;39; archive or a self-extracting .EXE archive.

Syntax

Update-ZipEntry -InputObject <Object> [-ZipFile] <ZipFile> [[-Name] <String>] [-Comment <String>] [-EntryPathRoot <String>] [-Passthru] [<CommonParameters>]

Description

Updates a &;39;.ZIP&;39; archive or a self-extracting .EXE archive by changing its inputs or by adding new ones.

Parameters

-InputObject <Object>

Content associated with an input archive. Types expected are: - One or more objects from type files or directories, - One or more file or directory names, - A string, - An array of bytes. For all other object types, there will be converted into string with &;39;ToString()&;39; method.

Required? True
Position? named
Default value  
Accept pipeline input? true (ByValue)
Accept wildcard characters? False

-ZipFile <ZipFile>

Target archive in which specified entry is updated. This parameter waits for a ZipFile object and not a file name.

Required? True
Position? 0
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-Name <String>

Each entry is associated with a name in the catalog. For files or directories, their names are automatically used for entries names, in the root of the archive. For strings or array of bytes, you must specify an entry name. The use of the &;39;-EntryPathRoot&;39; parameter will not influence this naming.

Required? False
Position? 1
Default value  
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

-Comment <String>

Comment associated with the entry. For entries such as strings or arrays, the comment will be their name by default : [String] or [Byte[]].

Required? False
Position? named
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-EntryPathRoot <String>

The entry will be updated or added in the specified path. By default, it is updatedd to the root of the tree contained in the archive. The value of this parameter must reference an existing directory path. You need to specify this parameter in order to avoid entry name clashes when compressing a recursive tree. This one allows to build the name of the entry relatively to the specified directory. For example, specifying &;39;C:\Temp\Backup&;39;, the treating building name will remove &;39;C:\Temp\Backup&;39; for each received file during recursive compression of &;39;C:\Temp\Backup&;39;. So, for files &;39;C:\Temp\Backup\File1.ps1&;39; and &;39;C:\Temp\Backup\Projet\File1.ps1&;39;, created entries in the catalog will be respectively : File1.ps1 Projet/File.ps1 By specifying a directory name different from the begining of the archive, it will trigger an error and will stop current archiving path.

Required? False
Position? named
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-Passthru <SwitchParameter>

Once the entry is updated in the archive catalog, it is issued in the pipeline.

Required? False
Position? named
Default value  
Accept pipeline input? false
Accept wildcard characters? False

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

Inputs

System.String, System.IO.DirectoryInfo, System.IO.FileInfo, System.Byte[], System.Collections.IDictionary, Ionic.Zip.ZipEntry

Outputs

Ionic.Zip.ZipEntry

Notes

If an entry already exists, it is updated. The LastModified property is populated with the current date and time. Updating a directory entry type only adds new elements, but does not delete entries that are no longer on the FileSystem. This is not a synchronization. By default the addition of an existing entry will trigger an exception.

Examples

EXAMPLE 1

PS C:\> try {         
$ZipFile=Get-Zipfile -Path C:\Temp\Test.zip
$File=Get-Item C:\Temp\Test.ps1 
Update-ZipEntry -InputObject $File -ZipFile $ZipFile
} finally {
$ZipFile.Close()
}

This commands update an entry in the &;39;C:\Temp\Test.zip&;39; archive: - The first instruction creates an archive object from a file name, - The second, from the current directory, updates archive entries corresponding to &;39;*.txt&;39; file names, - The third updates the file in the archive, - The fourth saves the archive on the disk and frees system ressources.

EXAMPLE 2

PS C:\> try {         
$ZipFile=Get-Zipfile -Path C:\Temp\Test.zip
Get-ChildItem *.txt|Update-ZipEntry -ZipFile $ZipFile
} finally {
$ZipFile.Close()
}

This commands update entries in the archive &;39;C:\Temp\Test.Zip&;39;: - The first instruction creates an archive object from a file name, - The second one updates all entries of the archive corresponding to &;39;*.txt&;39; file names from current directory, - The third updates or creates an entry containing a string, - The fourth saves the archive on the disk and frees system ressources.

EXAMPLE 3

PS C:\> try {         
$ZipFile=Get-Zipfile -Path C:\Temp\Test.zip
[string]$Text=Get-Content C:\Temp\Test.ps1|Out-String
Update-ZipEntry -InputObject $Text -Name MyText -ZipFile $ZipFile
} finally {
$ZipFile.Close()
}

This commands update a named entry in the archive &;39;C:\Temp\Test.Zip&;39; from a string: - The first instruction creates an archive object from a file name, - The second one reads a file text and sets the result into a string, - The third updates or creates an entry containing a string, - The fourth saves the archive on the disk and frees system ressources.

EXAMPLE 4

PS C:\> try {
$ZipFile=Get-Zipfile -Path C:\Temp\Test.zip         
ConvertTo-CliXml $PSVersionTable | Update-ZipEntry -Name 'PSVersiontable_clixml' -ZipFile $ZipFile
} finally {
$ZipFile.Close()
}

This commands update a named entry in the archive &;39;C:\Temp\Test.Zip&;39; from a serialized object: - The first instruction creates an archive object from a file name, - The second one serializes the object contained in the System.Management.Automation.PSVersionHashTable variable, then updates or creates named entry in the archive, - The third saves the archive on the disk and frees system ressources.

EXAMPLE 5

PS C:\> try {         
$ZipFile=Get-Zipfile -Path C:\Temp\Test.zip 
[byte[]] $Array=@(1..20)
Update-ZipEntry -InputObject $Array -Name MyArray -ZipFile $ZipFile
} finally {
$ZipFile.Close()
}

This commands update an entry named &;39;MyArray&;39; in the archive &;39;C:\Temp\Test.Zip&;39;: - The first instruction creates an archive object from a file name, - The second one adds the object contained in the &;39;&;39; variable, then updates or creates the entry named &;39;MyArray&;39;, - The third saves the archive on the disk and frees system ressources.

Related links

Unknown https://psionic.codeplex.com/wikipage?title=Update-ZipEntry-EN

PowerShell Support

  • PowerShell 2.0

Operating System Support

  • Windows 7
  • Windows 8
  • Windows 8.1
  • Windows Server 2008 all editions
  • Windows Server 2008 R2 all editions
  • Windows Server 2012 all editions
  • Windows Server 2012 R2 all editions

Last edited May 14, 2014 at 2:26 PM by LaurentDardenne, version 1

Comments

No comments yet.