【发布时间】:2020-01-22 00:29:19
【问题描述】:
在 5.1 版本的 powershell 中运行脚本时出现以下错误
在我删除文件超过 180 天的简单脚本下方,我尝试了一些解决方案,但我没有发现可能是什么错误。 (以下从葡萄牙语翻译成英语的错误)
“Out-File:无法验证'Encoding'参数中的参数。”文件\ DeleteLogFile_21_01_2020.log“参数不属于集合”未知;细绳;统一码; bigendianunicode; utf8; utf7; utf32; ASCII;默认; oem "由 ValidateSet 属性指定。提供集合中的参数并再次尝试该命令。在行上:1 个字符:36 + $ Log | Out-File -Append D:\Program files\DeleteLogFile_ $ LogDate.log + ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CategoryInfo: InvalidData: (:) [Out-File], ParameterBindingValidationException + FullyQualifiedErrorId: ParameterArgumentValidationError, Microsoft .PowerShell.Commands.OutFileCommand "
$logPath = "D:\Program files\NICE Systems\Logs"
$nDays = 10
$startTime = Get-Date
$Extensions = "*.*"
$LogDate = (Get-Date).ToString("dd_MM_yyyy")
$Files = Get-Childitem $LogPath -Include $Extensions -Recurse | Where-Object {$_.LastWriteTime -le (Get-Date).AddDays(-$nDays)}
foreach ($File in $Files)
{
if ($NULL -ne $File )
{
$Log = "`nData e Hora da Deleção: " + $startTime + ". O arquivo " + $File + " foi deletado do sistema."
$Log | Out-File -Append D:\Program files\DeleteLogFile_$LogDate.log
Remove-Item $File.FullName | out-null
}
}
【问题讨论】:
标签: powershell