Getting started with PowerShellLoopsOperatorsUsing ShouldProcessPowerShell ClassesSwitch statementWorking with ObjectsUsing existing static classesBasic Set OperationsPowerShell FunctionsSending EmailHandling Secrets and CredentialsPowershell RemotingPowerShell "Streams"; Debug, Verbose, Warning, Error, Output and InformationVariables in PowerShellCommunicating with RESTful APIsWorking with the PowerShell pipelinePowerShell Background JobsReturn behavior in PowerShellWorking with XML FilesIntroduction to PsakeUsing the progress barStringsTCP Communication with PowerShellSharePoint ModuleAliasesAutomatic VariablesEnvironment VariablesPowershell profilesEnforcing script prerequisitesUsing the Help SystemSplattingDesired State ConfigurationSigning ScriptsSecurity and CryptographyCSV parsingIntroduction to PesterModules, Scripts and FunctionsPowerShell.exe Command-LineCommon parametersParameter setsRegular ExpressionsPowerShell Dynamic ParametersWMI and CIMGUI in PowershellConditional logicURL Encode/DecodeMongoDBRunning ExecutablesError handlingHashTablesActiveDirectory modulepowershell sql queriesAutomatic Variables - part 2Package managementCmdlet NamingBuilt-in variablesCreating DSC Class-Based ResourcesPowershell ModulesPowerShell WorkflowsHow to download latest artifact from Artifactory using Powershell script (v2.0 or below)?Calculated PropertiesSpecial OperatorsAnonymize IP (v4 and v6) in text file with PowershellComment-based helpAmazon Web Services (AWS) Simple Storage Service (S3)Amazon Web Services (AWS) RekognitionPSScriptAnalyzer - PowerShell Script AnalyzerNaming ConventionsEmbedding Managed Code (C# | VB)Archive ModuleInfrastructure AutomationScheduled tasks moduleISE module

Archive Module

Other topics

Remarks:

See MSDN Microsoft.PowerShell.Archive (5.1) for further reference

Compress-Archive with wildcard

Compress-Archive -Path C:\Documents\* -CompressionLevel Optimal -DestinationPath C:\Archives\Documents.zip

This command:

  • Compresses all files in C:\Documents
  • Uses Optimal compression
  • Save the resulting archive in C:\Archives\Documents.zip
    • -DestinationPath will add .zipif not present.
    • -LiteralPath can be used if you require naming it without .zip.

Update existing ZIP with Compress-Archive

Compress-Archive -Path C:\Documents\* -Update -DestinationPath C:\Archives\Documents.zip
  • this will add or replace all files Documents.zip with the new ones from C:\Documents

Extract a Zip with Expand-Archive

Expand-Archive -Path C:\Archives\Documents.zip -DestinationPath C:\Documents
  • this will extract all files from Documents.zip into the folder C:\Documents

Syntax:

  • Expand-Archive / Compress-Archive
  • -Path
    • the path of the file(s) to compress (Compress-Archive) or the path of the archive to extract the file(s) form (Expand-Archive)
    • there are several other Path related options, please see below.
  • -DestinationPath (optional)
    • if you do not supply this path, the archive will be created in the current working directory (Compress-Archive) or the contents of the archive will be extracted into the current working directory (Expand-Archive)

Parameters:

ParameterDetails
CompressionLevel(Compress-Archive only) Set compression level to either Fastest, Optimal or NoCompression
ConfirmPrompts for confirmation before running
ForceForces the command to run without confirmation
LiteralPathPath that is used literaly, no wildcards supported, use , to specify multiple paths
PathPath that can contain wildcards, use , to specify multiple paths
Update(Compress-Archive only) Update existing archive
WhatIfSimulate the command

Contributors

Topic Id: 9896

Example Ids: 30444,30445,30446

This site is not affiliated with any of the contributors.