Eric,
Welcome to the forum. ![]()
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
Guide to Posting Code - Redux <---- Click
![]()
( !! Sometimes the preformatted text button hides behind the settings gear symbol.
)
I’d streamline your PowerShell code a little to avoid reading the directory twice but there’s actually nothing in your PowerShell code indicating that it should loop for some reason.
$CompleteFileList =
Get-ChildItem . -File
$oldestDate =
($CompleteFileList |
Sort-Object -Property CreationTime |
Select-Object -First 1).CreationTime.Date
$CompleteFileList |
Where-Object {
$_.CreationTime.Date -eq $oldestDate
} |
Remove-Item -WhatIf
It might help when you elaborate a little more how you run your code and especially why you’re running the PowerShell code from inside a batch file. That’s in the vast majority of the cases I know of unnessecary and error prone.