Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Creating Zip using PowerShell

$
0
0

Hi,

When try to execute below PS code, getting issue. 

$source = "D:\Scan" #All Sub Folders and Files (Including Empty Folder)
$destination = "D:\Temp_Scan\foo.zip"

If(Test-path $destination) {Remove-item $destination}

Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($Source, $destination) 

output 

PS C:\Windows\system32> Powershell.exe -ExecutionPolicy Bypass -File "D:\PS\Document.ps1"
Exception calling "CreateFromDirectory" with "2" argument(s): "The process cannot access the file
'D:\Scan\Company\ASCP.DFR' because it is being used by another
process."
At D:\PS\Document.ps1:7 char:1+ [io.compression.zipfile]::CreateFromDirectory($Source, $destination)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : IOException

Could you please help on this.

Thanks

Ramesh


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>