我想获得多个文件输入到Invoke-WebRequest
一个接一个地写入succuess或失败,取决于它是否有效。我怎样才能让我的代码工作在我的代码
Param(
[string]$path,
[string]$file,
[string]$spath
)
cls
$URI = "Link Can't be shown."
$path = "C:\Users\lfouche.ESSENCEHEALTH\Desktop\Monitoring Services and Sites\"
$spath = "C:\Users\lfouche.ESSENCEHEALTH\Desktop\txtFiles\"
$file = (Get-ChildItem 'C:\Users\lfouche.ESSENCEHEALTH\Desktop\Monitoring Services and Sites')
$inF = "$path" + "$file" + ".txt"
$otF = "$spath" + "$file"
foreach ($f in $file) {
wget $URI -Method post -ContentType "text/xml" -InFile $inF -OutFile $otF
}
if ($? -eq 'true') {
"Successful"
} else {
"Failure"
$LASTEXITCODE
}
我已经测试了你的改变我的脚本的这种变化,现在$文件变量已经存储了各种txt文件,为什么永远不会存在的原因,我无法弄清楚为什么或如何拿起这些不存在的文件 –
@LeandreFouche我不'随后。你是什么意思“存储了各种txt文件”? 'ForEach-Object'循环遍历'Get-ChildItem'产生的文件。每次迭代'$ file'都包含当前的文件名。 –
它清理了,我不知道为什么它拿起不包含在文件位置的不同文本文件 –