As a returning user of Windows after a long time using macOS I now need to do certain tasks with a command line/terminal. On macOS, I’ve gotten used to all the commands in iTerm 2 and have created several aliases to make certain commands easier to type.

I was trying to remove a directory and all its content recently on Windows and noticed that rm will only take you thus far as it doesn’t allow the removal of directories with content in it. I started looking at how this can be accomplished inside of PowerShell and while doing so I found the Remove-Item command. I dug a bit further into this command and found out it has a -recurse and -force parameters, these can be used to remove an entire directory and its content with it.

So if you want to remove a directory and its content on Windows using PowerShell, you can call the following function:

Remove-Item -path [path_to_directory] -recurse -force