Let's say I have a .txt file in the sample folder as shown in the path below:
C:\Users\Documents\sample\link.txt
Inside the link.txt, it has an URL to a website:
https://www.sample.com
Now, I'm looking for a way to open this URL in the .txt file using the PowerShell command. Ideally, I can open the URL with Chrome using a command like:
PS C:\Users> chrome C:\Users\Documents\sample\link.txt
Is there a way to do something like this?
CodePudding user response:
You can use Get-Content
Cmdlet to read the file contents and [System.Diagnostics.Process]::Start
API to start the Chrome application.
So to answer your question you can do,
Get-Content urls.txt | ForEach-Object {
[System.Diagnostics.Process]::Start("chrome", $_)
}