Powershell : QuickCMD : Import data from a .TXT file

Reading a Text File

Get-Content c:\scripts\test.txt

Import Text file content to a var

$var = Get-Content c:\scripts\test.txt

Using pipeline to pass the data to another cmdlet

Get-Content c:\scripts\test.txt | Foreach-Object {Get-Wmiobject -computername $_ win32_bios}

Count the number of lines of the array created from the Text file

Get-Content c:\scripts\test.txt | Measure-Object

Import only the first/last 5 lines from the Text file

Get-Content c:\scripts\test.txt -totalcount 5
Get-Content c:\scripts\test.txt | Select-Object -last 5

Get-Content Aliases

  • gc
  • type
  • cat

http://technet.microsoft.com/en-us/library/ee176843.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s