Powershell folder management problem
Posted on 2009-02-20
I am trying to solve a problem and I have a couple of different ways to address it that might work, but I'm not sure how to script either one.
The problem is that we have a folder structure where each client has a folder and there is a very specific folder tree (with one variation) that each folder should contain.... and ONLY those folders. For example, a client folder should contain only folders A, B, C and D, but sometimes folder A is allowed to contain a folder named "Backup". Also, only the folders A, B, C and D should contain files... not the parent client folder.
So, what I'd like to do is generate a report that lists all client folders that deviate from the norm. I'm envisioning a foreach loop and comparing to a list, but adding another subfolder layer is making things a bit complicated for my PowerShell newbie skills.
Alternatively, if I could just get a report that tells me with client folders have folders hierarchies that are more than 2 levels deep, that would be an immense help, but I can't seem to find any PowerShell commandlet that allows me to measure how deep a folder structure is. Perhaps I need to parse the output of something and delimit based upon backslash characters? That seems very un-PowerShell, though.
If anyone can point me in the right direction or another alternative for these issues, that would be fantastic. Ideally the application that's supposed to manage these folders would set permissions properly to prevent these issues.