简体   繁体   中英

How to generate the Zip using powershell with in same folder

Step1: need to zip below three files in same location with holds.zip Path: D:\Project\extensions\files inside this path having households filefolder xmldocument dll need to zip the file with these three files Step2:once zipped(holds.zip) delete the zip file and copy in D:\Project\extensions

using this command but not getting the required output Compress-Archive -Path D:\Project\extensions\files -DestinationPath D:\Project\extensions\files

I tried re-creating the scenario you mentioned as follows:

Created a directory "D:\Project\extensions\files" that contains the following items:

  1. A File Folder named "datadocs"
  2. An XML file named "script.xml"
  3. A DLL file named "config.dll"

在此处输入图像描述

I executed the below PS script and it archived the folder contents in same location:

$compress = @{
  Path = "D:\Project\extensions\files"
  CompressionLevel = "Fastest"
  DestinationPath = "D:\Project\extensions\files\holds.zip"
}
Compress-Archive @compress

在此处输入图像描述

Once the zip file was generated, I used the below cmdlet to delete it & move to "D:\Project\extensions" path:

Move-Item "D:\Project\extensions\files\holds.zip" "D:\Project\extensions\holds.zip"

在此处输入图像描述

Hope this solution meets your requirements!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM