PowerShell Command: Display Specific Text from a Website
The Get-Content cmdlet in PowerShell is a powerful tool for retrieving and displaying the contents of a file, including text from a website.
PowerShell Command Example
The following PowerShell command displays the text from the file file.txt on the website sitefocused.com:
Invoke-WebRequest -Uri "https://sitefocused.com/file.txt" | Select-Object -ExpandProperty ContentKey Concepts
Invoke-WebRequest: This cmdlet sends HTTP and HTTPS requests to a web page and returns the response.-Uri: This parameter specifies the uniform resource identifier (URI) of the web page to send the request to.Select-Object: This cmdlet selects specific objects or properties from the input object(s).-ExpandProperty: This parameter expands the value of the specified property into a separate object.
Formatting the Output
To display the output in a specific format, such as plain text, you can use the -OutFile parameter of the Invoke-WebRequest cmdlet. For example, the following command saves the output as a text file:
Invoke-WebRequest -Uri "https://sitefocused.com/file.txt" -OutFile "C:\output.txt"References
This article was last updated on .
Note: This article is for informational purposes only and does not constitute a page layout. It is intended to be used as a standalone HTML document and should not include any page layout tags such as div or hr.