delete home drives probably simple

Welcome Forums General PowerShell Q&A delete home drives probably simple

Viewing 2 reply threads
  • Author
    Posts
    • #257102
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      I keep banging my head against the wall figuring out why this wont work. from https://deployhappiness.com/delete-unused-home-folders-with-powershell/ there is a handy script which does exactly what i want. Of course there are some folders in there that i want to be excluded because someone decided to use them for a team.

      The script has a handy place to exclude drives $NamesToIgnore = “Jmoody” , but when i use more than one name in there it freaks out. i have tried a comma, semicolon, space, quotes and probably lots of things that i have forgotten and it never gives me the results that i expect.

      I just want to delete all of the old home drives from a share for users that no longer exist in AD with a list of exclusions that i can provide.

      of course there are users who have had name changes, but i think i have all of those included in my list of exclusions, and besides we back up that share so when the complain i can restore it.

      Thank you for the help, i am at the end of my rope!

    • #257111
      Participant
      Topics: 8
      Replies: 568
      Points: 2,170
      Helping Hand
      Rank: Community Hero

      I have several issues with that script so I rewrote it. The major issue that you’re encountering is that they correctly check $NamesToIgnore the first time with -NotContains but later do -notlike. So they are

      1. Checking this variable twice, once as an array and again as a single item.
      2. Don’t limit the $Folders/Get-Childitem to actual folders.
      3. Gathering -Properties * for no damn reason, never used.
      4. Doing the old make an array and append with += that should go away forever, but so many examples online still lead people to it.
      5. Pauses between each user, for what? The -Whatif should allow you to see it’s removing what you want.

      This should handle your needs.

      Another thing is if the directory is for a user that’s been deleted out of AD, it will not be removed. I did not change this logic either. Part of continuing is the aduser is able to be found.

    • #257237
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      Thank you very much, that is a huge help! I sincerely appreciate the quick response. sometimes working for a small company feels like working on an island when there are no co-workers to bounce stuff off of.

       

Viewing 2 reply threads
  • You must be logged in to reply to this topic.