Powershell - Retrieving Item



Cmdlet

Get-Content cmdlet is used to retrieve content of a file as an array.

Example 1

In this example, we'll read a file D:\Temp\Test\Test.txt

Type the following command in PowerShell ISE Console

Get-Content D:\temp\Test\test.txt

Output

You can see following output in PowerShell console.

Get-Content D:\temp\test\test.txt
;This is a test file.

Example 2

In this example, we'll read the size of the content of the file read.

Type the following command in PowerShell ISE Console

(Get-Content D:\temp\test\test.txt).length

You can see following output in PowerShell console.

(Get-Content D:\temp\test\test.txt).length
20
powershell_files_folders.htm
Advertisements