resgh
resgh

Reputation: 984

Powershell remove-item not working

Why is

dir E:\Music -File -Exclude *.mp3 -Recurse | foreach {del $_.FullName}

not working? I tested all the possibilities I could think of and it is still not working.

Thanks in advance.

Upvotes: 6

Views: 18593

Answers (3)

Forrest
Forrest

Reputation: 21

See Example 4 from the following command

 get-help remove-item -Examples

"Because the Recurse parameter in this cmdlet is faulty..."

would be my guess.

Upvotes: 2

user1462199
user1462199

Reputation:

I had the same issue, i used the following to fix it:

dir E:\Music -File -Exclude *.mp3 -Recurse | Remove-Item

Upvotes: 6

Shay Levy
Shay Levy

Reputation: 126722

The command looks ok and should work. Do you get any output if you remove the pipe to foreach-object? Are you using PowerShell v3? Give this a try, do you get WhatIf messages?

dir E:\Music -File -Exclude *.mp3 -Recurse | del -WhatIf

Upvotes: 3

Related Questions