The Get-Content
cmdlet is used to read the content from a file at a specified location using PowerShell. It reads line by line and returns the collection of objects.
Get-Content -Path "path to the file"
We need to pass the Path
to a file as a mandatory parameter. It also accepts the following other parameters:
TotalCount
: This is used to limit the number of lines Get-Content
returns.Tail
: This is used to get the last line of the file.This cmdlet returns a collection of objects, each representing a line of content in the file.
Educative helps software engineers grow their skill sets and reach their full potential.Text-based courses with interactive in-browser coding helps you learn faster and smarter.In-browser exercises. Free Sign-Up. No setup required. Learn at your own pace.
In the above code snippet, we read the content of the file data.txt
using the cmdlet Get-Content
on line 2.