0

I have a PowerShell script (Name: Get-OrphanHomeFolder.ps1 -- Author: Jaap Brasser -- http://www.jaapbrasser.com/new-script-find-orphaned-home-folders/) I downloaded and modified for locating and deleting orphaned home folders on our file server.

Due to the large number of users in the company, along with the slow performance of our restore software when enumerating folders to select for possible restorations, we have modified our home folder structure from the traditional layout of:

 D:
 |
 |--Home
     |
     |--100000
     |--102001
     |--115000
         etc.

To a structure like this:

D:
 |
 |--Home
     |
     |--100xxx
     |    |
     |    |--100000
     |    |--100001
     |    |--100002
     |      etc.
     |--102xxx
     |    |
     |    |--102000
     |    |--102001
     |    |--102002
     |      etc.
     |--115xxx
     |    |
     |    |--115000
     |    |--115001
     |      etc.

If I run the script using this command-line format (.\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\fileserver\homeshare\100xxx) it works great, but requires me to manually run it for each subfolder (100xxx, 101xxx, etc) containing a group of user home folders. Is there some way to have PowerShell enumerate all the subfolders that exist directly inside D:\Home, no deeper levels, and then use that to create a list/array of 100xxx, 101xxx, etc to run the main code against?

1
  • Get-Childitem should do what you want Commented Nov 21, 2014 at 19:08

2 Answers 2

1

Get all of the top-level directories, then iterate through them.

Get-childitem \\fileserver\homeshare -directory | foreach-object {.\get-orphanhomefolder.ps1 -homefolderpath $_.fullname}

If you have sufficient system resources available, you could run multiple instances of the script in parallel using start-job to reduce the overall execution time - but I would recommend limiting to no more than N-1 concurrent jobs where N is the number of CPUs on the system running the jobs. See http://www.poshpete.com/powershell/creating-a-throttle-for-background-tasks-without-rewriting-your-code-v2 for an example.

Sign up to request clarification or add additional context in comments.

2 Comments

I'll give that a shot. When it comes to PowerShell I'm lucky to even spell it right. :-) Given the late hour and being a Friday, I'll hold off testing until next week.
Built a test folder structure with some dummy folders. Ran the script and it worked like a charm. Thanks for your help.
1

Get-ChildItem supports wildcards in the path. It may be as simple as running this command:

.\Get-OrphanHomeFolder.ps1 -HomeFolderPath \\fileserver\homeshare\*

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.