将多个URL添加到此PowerShell脚本? [英] Add Multiple URLs to this PowerShell Script?

查看:100
本文介绍了将多个URL添加到此PowerShell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用脚本来调用URL,获取输出并将输出保存到文本文件中.一切都很好.但是,当我需要连续调用多个URL时,会导致CPU峰值,因为它多次启动/停止powershell.exe.在仍然保存输出的同时,我可以对每个URL使用for each技术吗?这是我的脚本:

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

请注意,这两个echo仅用于调试目的,并不重要.

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

推荐答案

这是您想做的事情吗?

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

我用7-8个网址写了一个urls.txt,对我来说效果很好.

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

这篇关于将多个URL添加到此PowerShell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆