Collections:
Other Resources:
Get File Content in Windows PowerShell
How to get the content of a file in Windows PowerShell?
✍: FYIcenter.com
You can use the "Get-Content" cmdlet to get the content of a file in Windows PowerShell.
"Get-Content" cmdlet gets the content of the item at the location specified by the path, such as the text in a file. It reads the content one line at a time and returns a collection of objects, each of which represents a line of content.
Note that "Get-Content" returns an array of Strings with each line of the file as an array element. "Get-Content" is not returning a single string of the entire file.
Here are some examples on how to use "Get-Content" cmdlet:
"`n--- Getting the first 5 lines of a file ---" Get-Content C:\Windows\System32\edit.hlp -First 5 "`n--- Getting the last 5 lines of a file ---" Get-Content C:\Windows\System32\edit.hlp -Last 5 "`n--- Getting the lines that contain 'cursor' from a file ---" Get-Content C:\Windows\System32\edit.hlp | Select-String "cursor"
If you run the script, you will get:
PS C:\fyicenter> .\Test.ps1 --- Getting the first 5 lines of a file --- @@!1!@ Edit Commands Cursor Movement Commands ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ --- Getting the last 5 lines of a file --- ♦ The path name is too long or contains invalid characters. ♦ The path name refers to a folder that doesn't exist. @@!9999!@ --- Getting the lines that contain 'cursor' from a file --- Cursor Movement Commands Delete - Delete the character that the cursor is on. Backspace - Delete the character to the left of the cursor. Tab - Move the cursor to next tab stop. Shift - Use the shift key in conjunction with the cursor Pastes the clipboard contents (if any) at the cursor position. Use the mouse or the F6 key to move the cursor to the window
⇒ Put Data into File in Windows PowerShell
⇐ Get Directory Properties in Windows PowerShell
2016-10-22, 2550🔥, 0💬
Popular Posts:
What is "McAfee Security Scan Component Host Service" in my Windows 7 service list? And how is "McAf...
What is the "World Wide Web Publishing Service (W3SVC)" system service on Windows Server 2012? Can I...
What is "Superfetch" in my Windows XP service list? And how is "Superfetch" service related to SysMa...
Where to find tutorials on managing Windows 8 scheduled tasks? Here is a collection of tutorials on ...
Extracting All Files from a ZIP File 1. Run WinZIP and select menu File > Open Archive. The "Open Ar...