4
リストが空のときにforeachループを保護する
Powershell v2.0を使用して、X日より古いファイルを削除します。 $backups = Get-ChildItem -Path $Backuppath | Where-Object {($_.lastwritetime -lt (Get-Date).addDays(-$DaysKeep)) -and (-not $_.PSIsContainer) -and ($_.Name -like "backup*")} foreach ($file in $backups) { Remove-Item $file.FullName; } ただし、$ backupsが空の場合、次のようになります。 Remove-Item : Cannot bind argument to parameter 'Path' because it is null. 私はもう試した: foreachを保護する if (!$backups) Remove-Itemの保護 if (Test-Path $file -PathType …
10
powershell