hi, I not a native English speaker, sorry if there any mistake,
some month ago i do this : https://forums.powershell.org/t/find-and-replace-2-byte-binary-file/15308/5
it works, but when i tried to open a 250mb file, the program cannot handle it,
i forgot the error log text, but it about “Get-Content”, and ram consume about 8GB,
my question is : how to solve this?
alternative : i tried to split the 250mb into 1.44mb using certain software, but when powershell read second data using same syntax but different file name (I guess it will be overwrite, turn out its not) the memory keep rising,
my second question is : what syntax to “flush”(it correct term right?) that ram data without closing powershell “window”?
Using a switch statement to read each line of my 225MB text file took 6 seconds compared to Get-Content (26 seconds). I didn’t notice any increase in system memory usage.
thank you for the answer,
I a newbie in this field, I just need some clarification:
A. the “switch -Regex -File $file” is a loop command that reads each line right?
B. the “$_” is the variable name of “the current line” right?
C. what “Default {}” command do? I google it and found nothing!
sorry if I bring more question, thank you again for the reply
Have you tried the StreamReader .NET class? I have never worked with files this large but it is the recommended approach when dealing with large amounts of text.
I am not sure I fully understand what you are trying to accomplish but try this:
$bytes = New-Object System.IO.StreamReader{D:\iso\iso.iso}
$bytes = $bytes.ReadToEnd()
Read-Host -Prompt “1.Press any key to continue”
#Convert the bytes to hex
$hexString = [System.BitConverter]::ToString($bytes)
Read-Host -Prompt “2.Press any key to continue”
thanks again for the reply,
i tried to find and replace byte data type in the binary file as I show in this link
that link works if file under 10mb, but i tried to edit 250mb of file,
please note, I am a newbie, and not a native English speaker, sorry if I rude
Have you tried what I suggested in my previous post? I don’t think $bytes was a string in your last attempt. Try adding a line with ‘bytes = $bytes.ReadToEnd()’.
the Get-Content is working, but when data under 10mb, if the data over 10mb, the powershell will comsume ram data over 8gb then crash,
this is the problem i face (i copy paste from my first post):
hi, I not a native English speaker, sorry if there any mistake,
some month ago i do this : https://forums.powershell.org/t/find-and-replace-2-byte-binary-file/15308/5
it works, but when i tried to open a 250mb file, the program cannot handle it,
i forgot the error log text, but it about “Get-Content”, and ram consume about 8GB,
my question is : how to solve this?
alternative : i tried to split the 250mb into 1.44mb using certain software, but when powershell read second data using same syntax but different file name (I guess it will be overwrite, turn out its not) the memory keep rising,
my second question is : what syntax to “flush”(it correct term right?) that ram data without closing powershell “window”?
If you split the file, you can use a foreach loop to read all the fragments. You can also assign the value to a variable which will be called after the file name. Then you can either set the variable to $null or remove it altogether which should free up RAM.
For instance, assume you have a folder with 100+ files, which contain each part of the original large file. The path is C:\Files in this example.
foreach ($Item in Get-ChildItem -Path C:\Files) {
New-Variable -Name $Item.Name -Value (Get-Content -Path $Item.FullName -Encoding Byte -ReadCount 0)
$bytes = Get-Variable -Name $Item.Name | Select-Object -ExpandProperty Value
$hexString = [System.BitConverter]::ToString($bytes)
# Here you would have to insert the code where you do something with variable $hexString
Remove-Variable -Name $Item.Name -Confirm: $false -ErrorAction SilentlyContinue
Remove-Variable -Name $hexString -Confirm: $false -ErrorAction SilentlyContinue
}