Read a file using PowerShell?
You can read a file without any PSSnapin by using Get-content
. And below you can find how to read a file, write on the file, and replace the existing content with new content.
1) read file
Get-Content -Path "D:\Logs\log20220805.txt"
2) write on file
Add-Content -Path "D:\Logs\log20220805.txt" -Value "new text"
3) replace with new content
Set-Content -Path "D:\Logs\log20220805.txt" -Value "replace with this text!"