Click to rate this post!
[Total: 0 Average: 0]
how to read a text file with powershell get-content
How does the Powershell Get-Content cmdlet work?
I present here, through some examples how to read a text file via Get-Content
Create a file “myfile.txt” for example in c:\ temp\.
We will give a variable name to this file $ file
the file contains 2 lines
line 1: hello
line 2: thank you
The basic command to read / retrieve the content of the file is “get-content“
In our example we will choose to store the content in a $ contents variable:
$contents = get-content $file
the result will be:
if we display the content of the file:
You now know how to read a file in powershell