Fehler:
Remove-Item : Das Argument kann nicht an den Parameter "Path" gebunden werden, da es NULL ist.
Bei Zeile:7 Zeichen:20
+ Remove-Item <<<< $dat.FullName -whatif
+ CategoryInfo : InvalidData: (

+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand
Script:
$Startordner="F:\";
$ordner = Get-ChildItem -Path $Startordner -recurse | Where-Object {$_.FullName -like "*protokolle" -and $_.PSIsContainer -eq $True}
foreach ($ord in $ordner) {
$datei = Get-ChildItem -Path $ord.fullname | Where-Object {$_.PSIsContainer -eq $False -and $_.lastwritetime -lt (Get-Date).AddMonths(-12)}
foreach ($dat in $datei) {
Remove-Item $dat.FullName -whatif
}
}