I´m totally new to Powershell and wanted to write a script that deletes all non-mp3 files in a directory.
My solution:
get-childitem -Recurse |
Where-Object {!($_.PSIsContainer)} |
Where {$_.Extension -ne ".mp3"} |
remove-item
What can be improved in this statement or could be written in another way.
Are there any problems with this statement?
Thank you.
I would use just one
Where-Objectcommand:If you’re certain that no directories have ‘mp3’ extension :
Remove
-whatIfto delete the files.