Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell压缩文件会引发OutOfMemory异常_Powershell_Zip_Compression_Out Of Memory - Fatal编程技术网

使用PowerShell压缩文件会引发OutOfMemory异常

使用PowerShell压缩文件会引发OutOfMemory异常,powershell,zip,compression,out-of-memory,Powershell,Zip,Compression,Out Of Memory,我正在使用PowerShell v5,并尝试使用Microsoft.PowerShell.archive模块中的Compress archivecmdlet对文件进行归档: Compress-Archive -LiteralPath $GLBSourcePathFull -CompressionLevel Optimal -DestinationPath $GLBArchiveFile 这可以完美地处理3个文件,它们的大小如下:16MB、341MB和345MB 但是,一旦遇到大于600MB的文

我正在使用PowerShell v5,并尝试使用Microsoft.PowerShell.archive模块中的
Compress archive
cmdlet对文件进行归档:

Compress-Archive -LiteralPath $GLBSourcePathFull -CompressionLevel Optimal -DestinationPath $GLBArchiveFile
这可以完美地处理3个文件,它们的大小如下:
16MB
341MB
345MB

但是,一旦遇到大于600MB的文件(大约),PowerShell就会抛出以下异常:

Exception calling "Write" with "3" argument(s): "Exception of type 'System.OutOfMemoryException' was thrown."
同样的事情也发生在大小超过
1GB
的文件上

为了给我的情况添加更多的上下文,我正在尝试将文件从本地文件夹压缩到公司内的一个网络位置,但是我怀疑这有什么区别,因为我在本地PC上测试这一点只是为了得到相同的结果

你以前遇到过这种情况吗?在输出zip之前,它是否试图将整个文件读入内存,而不是直接写入磁盘?或者,PowerShell在默认情况下可以使用的内存有限制

我知道还有一些其他的解决方案,比如
7Zip4powerShell
module,但目前我不允许使用任何开源软件,因此我想了解我目前的情况,以及我可能如何解决这个问题


感谢您的评论。

Compress Archive cmdlet可能使用了一种简单的方法,将整个源文件和目标存档加载/映射到内存中,因为您显然使用的是32位PowerShell这些文件(以及PowerShell进程代码和进程使用的其他数据)不适合2GB的进程地址空间(如果是较大的AddressWare,则为3-4GB)

具有大量RAM(例如32GB)的计算机上的64位PowerShell成功压缩1GB以上的文件


如果您无法使用32位PowerShell和内置cmdlet,请尝试将文件拆分为100MB文件,并使用一些描述性文件名,以便能够在解包脚本中加入这些文件。显然,如果没有重新组装脚本,任何人都无法使用这样的存档。

如果没有尝试过它:在这种情况下,.net类可能工作得更好:?