我在一个大目录上运行了这个函数:
定义
# (searches for all ips within files in the current directory recursively)
function searchips
{
param(
[Parameter(Mandatory=$false)][string]$dir = $(pwd)
)
ls -Recurse -Force `
| Select-String -Pattern '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' -AllMatches `
| ? {
$matches = ($_.Matches | Select-Object -Unique)
return $matches.Count -gt 1 -or $matches[0].Value -ne '127.0.0.1'
} `
| select Path,Matches,FileName,LineNumber,Line `
| Format-Table -AutoSize `
| Out-String -Width 4096
}
呼叫
PS C:\path\to\huge> searchips hugeDirectory >> outfile.txt
但是我每次都会遇到这个错误:
out-lineoutput : 引发了类型为 'System.OutOfMemoryException' 的异常。 At C:\Users\myUserName\Documents\WindowsPowerShell\profile.ps1:73 char:2 + ls -Recurse ` + ~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [out-lineoutput], OutOfMemoryException + FullyQualifiedErrorId : System.OutOfMemoryException,Microsoft.PowerShell.Commands.OutLineOutputCommand
目前,我的PS内存设置如下:
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Shell
Name Value Type ---- ----- ---- AllowRemoteShellAccess true System.String IdleTimeout 7200000 System.String MaxConcurrentUsers 10 System.String MaxShellRunTime 2147483647 System.String MaxProcessesPerShell 25 System.String MaxMemoryPerShellMB 9000000 System.String MaxShellsPerUser 30 System.String
有什么想法吗?