Test-ZipFile

Synopsis

Tests if a file is in PkZip format.

Syntax

Test-ZipFile [-Path] <Object> [-Password <String>] [-isValid] [-Check] [-Repair] [<CommonParameters>]

Test-ZipFile [-Path] <Object> [-Password <String>] [-isValid] [-Check] [-Repair] [-Passthru] [<CommonParameters>]

Description

Tests if a file is in PkZip format. During this test, it is also possible to check if the archive is valid and in this case, to attempt to fix it. By default, simple errors are thrown.

Parameters

-Path <Object>

Archive file name to test. Can be a file object or a string. In this last case, generic characters can be used (* , ? , [A-D] ou [1CZ]).

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

-Password <String>

Password, necessary if the archive is protected by a password. If you need to test an archive with a password, do not use the '-IsValid' parameter, because in this case the result returned is always false. Use only the '-Password' parameter and/or the '-Check' parameter. If the password is wrong the result returned is false.

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

-isValid <SwitchParameter>

Indicates whether the archive appears to be valid. This function can therefore returns True when the contents of the archive is wrong. If a file is not an archive and the '-isValid' parameter is specified, then the simple errors are not generated. If you need to test an archive with a password, do not use this parameter, but the '-Password' parameter and/or the '-Check' parameter.

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

-Check <SwitchParameter>

Verify if the archive catalog is correct. This verification is stricter than that made ​​with the '-isValid' parameter. So it can returns False although the file is considered as a valid archive. If you need to test an archive with a password, use this parameter with or without the ''-Password'' parameter.

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

-Repair <SwitchParameter>

Attempts to repair if archive is corrupt.

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

-Passthru <SwitchParameter>

Outputs the name of the archive file in the pipeline. If ''-isValid'' parameter is also specified, then the names of files that are considered invalid will not be issued in the pipeline and no single error is triggered. This behavior is similar to a filter where only the names of valid files would be issued in the pipeline. The archive objects returned are not locked, pay attention to your use of these objects scenarios.

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.FileInfo

Outputs

System.Boolean

Notes

Examples

EXAMPLE 1

PS C:\> "C:\Temp\*.*"|Compress-ZipFile "C:\Temp\Test.zip"
Test-Zipfile "C:\Temp\Test.zip"

The first line creates a Zip archive. The second tests if the file is a 'PkZip' archive format. The result of the execution is 'True'.

EXAMPLE 2

PS C:\> "C:\Temp\*.*"|Compress-ZipFile "C:\Temp\Test.zip"
ConvertTo-Sfx  -path "C:\Temp\Test.zip" 
Test-Zipfile "C:\Temp\Test.exe"

The first line creates a zip archive. The second creates a self-extracting archive. The third tests if the file is a 'PkZip' archive format. It is found that a self-extracting archive is considered as a valid archive. The returned value is 'True'.

EXAMPLE 3

PS C:\> Get-Service Winmgmt|Test-ZipFile

The result of the execution is 'False' because the object received, converted into string, does not reference a ZIP file archive.

Related links

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

Comments

No comments yet.