在继续我之前的文章时,我现在正在尝试在Invoke-WebRequest
循环中运行ForEach
该脚本似乎运行良好,但仅返回一个输出。有打印机IP地址
以下是完整的脚本:
$printers = get-content "c:\TMP\printers.txt"
ForEach ($IP In $printers)
{
$R=Invoke-WebRequest $IP -SessionVariable session1
#B553 - name in Html
$R.Forms[0].Fields["B553"]="user"
$R.Forms[0].Fields["password"]="pass"
$Invoke1=Invoke-WebRequest -Uri ($IP + $R.Forms[0].Action) -WebSession $session1 -Method POST -Body $R.Forms[0].Fields
Start-Sleep -s 5
$Invoke2=Invoke-WebRequest $IP -WebSession $session1
$amount=@($Invoke2.AllElements | where tagname -EQ "dd" | Select -ExpandProperty innerText)[23]
#$amount
#Remove-Variable $amount
$amount| out-file -filepath C:\TMP\dump_txt.txt -append -width 200
#$amount| export-csv -Path C:\TMP\dump_csv.csv
}
也许我需要在脚本结尾处结束-WebSession
?
还尝试过Remove-Variable $amount
,但它存储了数组值,告诉我找不到名称为