Remove-ZipEntry

Synopsis

Deletes one or more entries from an archive.

Syntax

Remove-ZipEntry -InputObject <Object> [-ZipFile] <ZipFile> [[-Name] <String>] [<CommonParameters>]

Remove-ZipEntry [-ZipFile] <ZipFile> [-Query <String>] [-From <String>] [<CommonParameters>]

Description

Deletes one or more entries from a '.Zip' archive or from a self-extracting archive .exe.

Parameters

-InputObject <Object>

Content associated with an input archive. Types expected are: - One or more objects from type files or directories, - A string referencing an entry. If it references a directory name, it must end with the '/' character, - An object fro mtype ZipEntry, - An array of objects from type ZipEntry, - An array of strings or objects. In this last case his contents will be changed to String. All others arrays types, other than those indicated above, will throw an exception. For all other object types, there will be converted into string.

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

-ZipFile <ZipFile>

Target archive in which specified entry is removed. 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.

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

-Query <String>

Specifies a search for data to be deleted from the Zip archive. For more information on writing and query syntax, see the Help file about_Query_Selection_Criteria or the documentation of Ionic dll (Chm help file). Warning, there is no consistency check on the contents of the query, for example 'size <100 byte AND Size> 1000 byte' will not cause an error, but no file will be selected.

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

-From <String>

Specifies the archive folder in which entries will be deleted. A folder name in an archive has the following syntax : 'FolderName/' or 'FolderName/SubFolderName/'. The use of this parameter needs to specify the '-Query' parameter, otherwise an exception will be thrown.

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

Outputs

Notes

Examples

EXAMPLE 1

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

These statements remove, if it exists, the entry 'Test.ps1' from the root of 'Test.zip' file.

EXAMPLE 2

PS C:\> try {         
$ZipFile=Get-Zipfile -Path C:\Temp\Test.zip
'Test.ps1'|Remove-ZipEntry -ZipFile $ZipFile
} finally {
$ZipFile.Close()
}

These statements remove, if it exists, the entry 'Test.ps1' from the root of 'Test.zip' file.

EXAMPLE 3

PS C:\> try {         
$ZipFile=Get-Zipfile -Path C:\Temp\Test.zip
$Tab=@('Test.ps1','Setu1.ps1')
,$Tab|Remove-ZipEntry -ZipFile $ZipFile
} finally {
$ZipFile.Close()
}

These statements remove, if it exists, the entries 'Test.ps1' and 'Setup.ps1', contained in the array of string $Tab, from the root of 'Test.zip' file.

EXAMPLE 4

PS C:\> try {         
$ZipFile=Get-Zipfile -Path C:\Temp\Test.zip
$Tab=@('Test1.ps1';Get-ChildItem *.XML;Get-Content C:\Temp\ListeFileName.txt)
,$Tab|Remove-ZipEntry -ZipFile $ZipFile
} finally {
$ZipFile.Close()
}

Those instructions delete from the root of the 'Test.zip' file and if it exists : - The 'Test.ps1' entry, - All entries finishing with '.XML' and - All names of the entries contained in the 'C:\Temp\ListeFileName.txt' file.

EXAMPLE 5

PS C:\> try
{          
$ZipFile=Get-ZipFile -path C:\Temp\archive.zip -ZipErrorAction Skip -Verbose 
Remove-ZipEntry -ZipFile $ZipFile -Query 'name = *.txt'
} finally {
$ZipFile.Close()
}

Those instructions, using a query, delete all entries ending with '.TXT' from the root of the 'Test.zip' file.

EXAMPLE 6

PS C:\> try
{          
$ZipFile=Get-ZipFile -path C:\Temp\archive.zip -ZipErrorAction Skip -Verbose 
Remove-ZipEntry -ZipFile $ZipFile -Query 'name = *.txt' -From 'Doc/' 
} finally {
$ZipFile.Close()
}

Those instructions, using a query, delete all entries ending with '.TXT', in the 'Doc/' directory of the 'Test.zip' file.

Related links

Unknown https://psionic.codeplex.com/wikipage?title=Remove-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 11:45 AM by LaurentDardenne, version 2

Comments

No comments yet.