Add Multiple URLs to this PowerShell Script?

喜夏-厌秋 提交于 2019-12-25 14:47:23

问题


I am using a script to call URLs, get the output, and save the output to a text file. It all works great. However, when I need to call multiple URLs in succession it causes CPU spikes because it is starting/stopping powershell.exe so many times. Is there a whay I could use a for each technique for each URL while still saving the output? Here is my script:

$content = Get-Content $PSScriptRoot\urls.txt

echo "Testing for $content"

(Invoke-WebRequest -Uri "$content").Content |
    Out-File -FilePath "$PSScriptRoot\out.txt"

$status = Get-Content $PSScriptRoot\out.txt

Note that the two echo are just for debugging purposes, don't really matter.


回答1:


Is this Something that you wanted to do?

$contents = Get-Content $PSScriptRoot\urls.txt
foreach($content in $contents){
(Invoke-WebRequest -Uri "$content").Content |Out-File -FilePath $PSScriptRoot\out.txt -Append
}

I Wrote a urls.txt with 7-8 urls,And it worked fine for me.



来源:https://stackoverflow.com/questions/44924385/add-multiple-urls-to-this-powershell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!