我正在开发一个可以从外部文本文件中删除文件的脚本。该脚本运行良好但现在,我想通过将错误输出到外部文本文件来改进它。
我尝试过尝试和捕获,但我不知道为什么它不起作用。这是相关的ps1代码:
$LogFile = "log.txt"
$ErrorFile = "error.txt"
Get-ChildItem -Path (Get-Content liste.txt) |
ft FullName -HideTableHeaders |
Out-File $logfile -Append
foreach ($i in Get-Content liste.txt) {
try {
Get-ChildItem -Path $i -Include *.* -Recurse | Remove-Item
Write-Output "tout est supprimé"
} catch {
Write-Output "Something's wrong"
}
}
答案 0 :(得分:0)
您需要-ErrorAction Stop
get-childitem