Power shell 脚本(删除旧的备份文件(
$date = (get-date).AddDays(-10)
$files = Get-ChildItem -Path "\sc-sqlbackupssqlbackupsSA144Milliteste" -Files | ?{$_.LastWriteTime -lt $date}
foreach ($file in $files) {
Write-Host "Removing $file"
$file | Remove-Item -ErrorAction SilentlyContinue
}
上述命令在Windows Powershell(Windows 10(中运行没有问题。但是当我使用相同的命令创建 SQL Server 作业时,我得到
错误
作业步骤在 PowerShell 脚本中的第 2 行收到错误。 对应的行是
'$files = Get-ChildItem -path "\\sc-sqlbackups\sqlbackups\SA144\Milli\teste" -File | ?{$_.LastWriteTime -lt $date} '.更正脚本并重新计划作业。PowerShell 返回的错误信息是:"找不到与参数名称'文件'匹配的参数。
-Files
在旧的PS Verisons中不受支持。 改用Where-Object { $_.PSIsContainer -eq $false }
!