I'm trying to get a list of certain files from a directory and then delete them. I'm sure I'm doing something very basic wrong...but I can't seem to figure out what. Here is what I did:
$file = Get-ChildItem -recurse | where-object {$_ -match "HTTP*.PDF"}
I ran $file | gm to make sure it has the delete method, which it does. And I checked $file to make sure it has the files I want to delete. Then I ran this:
$file.delete()
Method invocation failed because [System.Object[]] doesn't contain a method 'delete'
how come it shows a delete method when I run $file | gm then?
Just to see I tried $file | foreach-object {$_.delete()}, which didn't return an error but didn't actually delete anything.