Powershell

How to Use the Expand-Archive Cmdlet in PowerShell?

An archive or zip file is a package that contains multiple files compressed in a single file. The “Expand-Archive” cmdlet extracts or expands the archive files to a specified location or folder in PowerShell. When files are compressed or archived, they can be shared with friends via email. Moreover, the virus can not affect the archived files.

This tutorial will cover the details related to the “Expand-Archive” cmdlet.

How to Utilize the PowerShell’s Expand-Archive Cmdlet?

As described earlier, to extract the content of a particular archive file into a desired location or folder, the “Expand-Archive” cmdlet can be used. Overview the below-given examples to learn the working of the “Expand-Archive” cmdlet.

Example 1: Use the Cmdlet “Expand-Archive” to Extract the Archive’s Content

Use the provided cmdlet to expand an archive in PowerShell:

Expand-Archive -LiteralPath "C:\Docs\New_File.zip" -DestinationPath C:\Docs

 
According to the above-stated code:

    • Initially, specify the “Expand-Archive” cmdlet.
    • Then, mention the “-LiteralPath” parameter and assign it to the zip file.
    • Lastly, add the “-DestinationPath” parameter and assign the destination path.

 

Example 2: Overwrite an Existing Zip File Using the “Expand-Service” Cmdlet in PowerShell

To overwrite the already extracted content in a directory, use the “-Force” parameter:

Expand-Archive -Path "C:\Docs\File.zip" -DestinationPath "C:\Docs" -Force

 

That’s all! We have compiled different examples related to the “Expand-Archive” cmdlet in PowerShell.

Conclusion

The “Expand-Archive” cmdlet in PowerShell is used for extracting or expanding the contents of a file into a specific location. This post has covered the details and working of the “Expand-Archive” cmdlet in PowerShell.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.