Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
849 views
in PowerShell by 66 69 85
Is it possible to read files by using PowerShell? in some programming languages you need to call some classes like C# you must call `system.IO`.

Is there any PowerShell Snapin that needs to use for reading files using PS?

1 Answer

1 like 0 dislike
by 66 69 85
 
Best answer

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!"
If you don’t ask, the answer is always NO!
...