Search code examples
powershellpowershell-2.0powershell-3.0powershell-4.0

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


Solution

  • 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"

    enter image description here

    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
    

    enter image description here

    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"
    

    enter image description here

    Hope this solution meets your requirements!