To piggyback onto this question, PowerShell script to delete files from list and output list of deleted file, I am trying to accomplish something similar. I have a list of usernames that match the names of some folders on our network file server. Not all of the usernames in the list are going to have home folders created, some may simply not exist.
My psuedocode looks something like this:
- Load the list of users
- For each user check to see if they have a directory or not
- If they have a directory, forcefully and recursively remove it
Here is some code that I have been working unsuccessfully with:
$Termed_Users = "C:\Data\Termed_Users.csv"
$Home_Folders = "X:"
$UserList = Import-Csv $Termed_Users
$UserList | ForEach-Object {
$ID = $_.ID
$User_Home = $Home_Folders + "\" + $_.ID }
If ( Test-Path $User_Home ) { Remove-Item -Recurse -Force $User_Home }