< Back

Compress-CItem

Sun Jan 12, 2020 9:01 pm

NAME Compress-CItem



SYNOPSIS

Compresses a file/directory using the `DotNetZip` library.





SYNTAX

Compress-CItem [-Path] <String[]> [[-OutFile] <String>] [-UseShell] [-Force] [-WhatIf] [-Confirm]

[<CommonParameters>]





DESCRIPTION

You can supply a destination file path, via the `OutFile` parameter. If the file doesn't exist, it is created. If

it exists, use the `-Force` parameter to overwrite it.



Each item added to the ZIP file will be added to the root of the file, with a name matching the original

file's/directory's name. For example, if adding the file `C:\\Projects\\Carbon\\RELEASE NOTE.txt`, it would get added

to the ZIP file as `RELEASE NOTES.txt`.



If you don't supply an output file path, one will be created in the current user's TEMP directory.



A `System.IO.FileInfo` object is returned representing the ZIP file. If you're using the `WhatIf` switch, nothing

is returned.



Microsoft's DSC Local Configuration Manager is unable to unzip files compressed with the `DotNetZip` library (or

the `ZipFile` class in .NET 4.5), so as an alternative, if you specify the `UseShell` switch, the file will be

compressed with the Windows COM shell API.





PARAMETERS

-Path <String[]>

The path to the files/directories to compress.



Required? true

Position? 1

Default value

Accept pipeline input? true (ByPropertyName)

Accept wildcard characters? false



-OutFile <String>

Path to destination ZIP file. If not provided, a ZIP file will be created in the current user's TEMP directory.



Required? false

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-UseShell [<SwitchParameter>]

Uses the Windows COM shell API to create the zip file instead of the `DotNetZip` library. Microsoft's DSC

Local Configuration Manager can't unzip files zipped with `DotNetZip` (or even the .NET 4.5 `ZipFile` class).



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Force [<SwitchParameter>]

Overwrites an existing ZIP file.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



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 (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

System.IO.FileInfo





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Compress-CItem -Path 'C:\\Projects\\Carbon' -OutFile 'C:\\Carbon.zip'



Demonstrates how to create a ZIP file of the `C:\\Projects\\Carbon` directory.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Get-ChildItem -Path 'C:\\Projects\\Carbon' | Where-Object { $_.PsIsContainer} | Compress-CItem -OutFile

'C:\\Projects\\Carbon.zip'



Demonstrates how you can pipe items to `Compress-CItem` for compressing.









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Compress-CItem -Path 'C:\\Projects\\Carbon' -OutFile 'C:\\Carbon.zip' -UseShell



Demonstrates how to create a ZIP file with the Windows shell COM APIs instead of the `DotNetZip` library.











RELATED LINKS

https://www.nuget.org/packages/DotNetZip

Expand-CItem

Test-CZipFile