Powershell 向多个目标调用 Web 请求 [英] Powershell invoke web request to multiple targets
本文介绍了Powershell 向多个目标调用 Web 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我第一次使用 powershell,我想知道如何以最简单的方法调用多个目标
My first time using powershell and i would like to know how i could invoke multiple targets in the easiest method possible
例如使用 curl 我可以执行以下操作
for example using curl i can do the following
curl "http://root:pass@10.21.1.(196,197,198,199,200}/axis-cgi/restart.cgi"
到目前为止,我已经创建了一个脚本来将单个 Web 请求发送到一个 url,如下所示
So far i have created a script to send a single web request to a url as below
$username = "root"
$password = "pass" | ConvertTo-SecureString -asPlainText -Force
$cred = New-Object
System.Management.Automation.PSCredential($username,$password)
$res = Invoke-WebRequest http://10.21.66.21/axis-cgi/restart.cgi -Credential
$cred
但我想将此命令发送到大约 100 台设备,有没有办法做到这一点.
But i would like to send this command to around 100 devices, is there a way of doing this.
欢迎任何帮助
推荐答案
使用范围运算符可能适用于您的情况:
Using the range operator might work in your case:
(196..200) | ForEach-Object {
$res = Invoke-WebRequest http://10.21.66.$_/axis-cgi/restart.cgi -Credential $cred
}
可以使用$_
在管道中访问范围内的数字,您可以将其放入目标IP地址
The numbers in the range can be accessed in the pipeline using $_
which you can put into your target ip address
这篇关于Powershell 向多个目标调用 Web 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文