Read a whole file as one string with Get-Content -Raw
Without -Raw, Get-Content splits files into line arrays — a trap that breaks multi-line regex and exact string comparisons.
01Command
$ $html = Get-Content 'C:\Temp\page.html' -Raw02What it does
By default Get-Content emits one string object per line, so saving it to a variable gives you an array — and (Get-Content $f) -replace 'a','b' then writes the file back with different line endings. -Raw returns one string with original line endings intact, which is what multi-line regex matching and byte-exact comparisons need. The companion forgotten switch is -Delimiter, e.g. -Delimiter ';' for semicolon files.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Get-Content | Microsoft LearnEvidence: Microsoft documents the -Raw switch, which ignores line breaks and returns the file content as a single string.
- Get-Content - PowerShellEvidence: SS64 explains -Raw returns one string preserving newline characters, versus the default line-by-line array.
Last verified: 2026-09-17 · Category: Files & Folders
06Related solutions
Diagnose NTFS file system errors and bad sectors on any volume — including the system drive while Windows is running — before committing to a repair.
Robocopy is Windows' built-in robust file copier: use /MIR to keep a destination folder as an exact one-way mirror of a source, resumable and restartable.
Search inside text files and logs with regex, returning file, line number and match.