gpt4 book ai didi

Powershell 给出 Get-Content : Exception of type 'System.OutOfMemoryException' was thrown

转载 作者:行者123 更新时间:2023-12-05 06:44:36 30 4
gpt4 key购买 nike

我正在尝试使用以下命令在 powershell 中读取大小为 1 GB 的文件,

$data = Get-Content - 编码字节 $filepath

它抛出以下错误:获取内容:引发了“System.OutOfMemoryException”类型的异常。

搜索网络,发现运行下面的命令修复了它,但这对我不起作用。设置项 wsman:localhost\Shell\MaxMemoryPerShellMB 4096

最佳答案

默认 MaxMemoryPerShellMB = 1024MB如果你想读取大文件说 1GB 或更大,您需要设置 MaxMemoryPerShellMB。

使用下面的代码设置 MaxMemoryPerShellMB-

    function setpsmem
{
$winrmstatus = (get-service WinRM).Status
if ($winrmstatus -eq 'Running')
{
$currentpsmem = (Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB).value
if ($currentpsmem -le 4096)
{
Set-Item WSMan:\localhost\Plugin\Microsoft.PowerShell\Quotas\MaxMemoryPerShellMB 4096
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 4096
Restart-Service winrm
$currentmemory = (Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB).value
Write-Host "Script assign $currentmemory[MB] of memory to PowerShell" -ForegroundColor Green
}
else
{
$currentpsmem = (Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB) | Select-Object value
Write-Host "Powrshell has $currentpsmem[MB] of memory." -ForegroundColor Green
}
}
else
{
Write-Host "WinRM services is not running on current host." -ForegroundColor Red
}

} setpsmem

试一试。

关于Powershell 给出 Get-Content : Exception of type 'System.OutOfMemoryException' was thrown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28503765/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com