There's an important principal in programming called Don't Repeat Yourself (or DRY). This says that if there is any repeated code, then that is usually a bad thing. So let's identify the non-repeated code, and start with that. This is the stuff that changes:
desktop
contacts
documents
Downloads
Music
Pictures
Videos
We could put that in a file, but that's probably overkill here, so let's just put that in an array:
$dirNames =
"desktop",
"contacts",
"documents",
"Downloads",
"Music",
"Pictures",
"Videos"
Now we can just operate on the array:
foreach ($dirName in $dirNames)
{
Remove-Item -Path "C:\users\test_removal_account\$dirName\*" -Recurse -WhatIf
}
Notice I put -WhatIf
on the Remove-Item
. That just makes the command tell you what it is going to do instead of actually doing it. This is useful for testing purposes. You can remove it when you are happy the script does what you want.
This script as it stands is dangerous. Recursive deletes must be treated with respect. If you accidentally blow away someone's work, you could ruin their life. You may even accidentally blow away all your own work and ruin your own life. You have to think about this sort of thing as a responsible engineer.
Of course, the "test_removal_account" makes the script pretty benign as it stands, but I don't know what you are going to replace that with in the real script.
I don't think a script ought do anything destructive if you just run it.
If it were me, I would put in a confirmation check before deleting. I would get the user to type in something, such as "really delete" before doing the delete.