Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7512835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:59:39+00:00 2026-05-29T23:59:39+00:00

To piggyback onto this question, PowerShell script to delete files from list and output

  • 0

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 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:59:41+00:00Added an answer on May 29, 2026 at 11:59 pm

    The issue is in your ForEach-Object pipe.

    You are continually reassigning the $User_Home variable, and cycle through the whole list before attempting any deletes. Move your deletion into that script block:

    $UserList | ForEach-Object {    
       $ID = $_.ID  
       $User_Home = $Home_Folders + "\" + $_.ID
       Remove-Item -recurse -force $User_Home -erroraction silentlycontinue }
    

    I also removed the test since it won’t matter – you will try to delete them all and ignore the errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apache Pig can load data from Hadoop sequence files using the PiggyBank SequenceFileLoader :
From PHP.net: http://www.php.net/manual/en/function.pfsockopen.php I understand the gist of what this function accomplishes, but I'm
I am drawing a list of file & folder names on a panel and
I am trying to get a series of ids from a local cube to
I have a Pig job which analyzes log files and write summary output to
This question applies to WordPress, but maybe someone knows if it applies universally? Is
This question is to piggy back off of a previous one I asked yesterday
from http://directwebremoting.org/dwr/reverse-ajax/index.html , it stated it supports polling, comet,piggyback. does that mean when we
I have this question in mind regarding optimazation of compiler when it comes to
I'm putting up a site using Wordpress and I'd like to piggyback on its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.