I am successfully deleting files as expected using the below command; however, I\'d like to get a count of the items deleted.
Get-ChildItem $dPath -Filter \"*.bl
Collect the items in a variable, get the count of that list, then remove the items:
$items = Get-ChildItem -Path C:\Temp -Filter "*.blah"
$cnt = $items.Count
$items | Remove-Item
or count the items that were successfully deleted:
$cnt = 0
Get-ChildItem -Path C:\Temp -Filter "*.blah" | ForEach-Object {
Remove-Item $_.FullName
if ($?) { $cnt++ }
}
You can write the FileInfo
returned by Get-ChildItem
to the output pipeline after deleting them:
Get-ChildItem -Path $path |
ForEach-Object { Remove-Item $_; Write-Output $_} |
Measure-Object