【发布时间】:2021-02-19 11:07:16
【问题描述】:
我正在编写一个 powershell 脚本以在 C:\ 驱动器中大小为 47 GB 的远程计算机上创建一个 zip 文件夹。该文件夹也在 C:\ drive 中。 C:\ 驱动器有 66gb 可用空间,但仍然给我“没有足够的内存资源”的错误来创建 zip,所以我尝试创建从 C:\ 到 H: 的 zip。我的 H:\ 驱动器有 121 GB 可用空间,但仍然给我错误。 我附上了这两个错误的屏幕截图。
$curentDirectory = $PSScriptRoot
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
Write-Output "Script Current Directory is:"$curentDirectory
Write-Output "Reading Configuration From :"$curentDirectory"/config.xml"
$myData = [xml](Get-Content $curentDirectory"/config.xml" -ErrorAction Stop)
$machineName = $myData.'tangoEnvironment'.VM01.machineName
$machineDrive= $myData.'tangoEnvironment'.VM01.machineDrive
$remoteUser = $myData.'tangoEnvironment'.VM01.remoteUser
$remotePassword = $myData.'tangoEnvironment'.VM01.remotePassword
$userCred = New-Object Management.Automation.PSCredential($remoteUser, (convertto-
securestring $remotePassword -asplaintext -force))
Invoke-Command -ComputerName $machineName -Credential $userCred -ScriptBlock {
Write-Host ""
Write-Host "Response from Jump Server($env:COMPUTERNAME) ..."
# Rest of service
Compress-Archive -Path C:/Humera -DestinationPath H:"/Humera.zip"
}
cmd /c pause
【问题讨论】:
-
ZIP 对存档的大小和存档内的文件有限制。尝试改用 7-zip。
-
磁盘空间不是这里的问题。
Invoke-Command表示代码在远程 shell 中运行,并且 shell 可以分配多少内存(RAM,而不是磁盘空间)会有限制。 -
欢迎来到 Stack Overflow。除了上述两个有效点之外,ZIP 在工作区中工作,并根据该工作区写入其输出。在某些情况下,它需要至少 100% 的额外空间才能实现其目标。
标签: powershell zip powershell-remoting