Simon
 New Member Posts:4

 |
| 08 Sep 2010 10:22 PM |
|
Hi All, I have been trying to write a powershell script for nearly a week now that lists all the folders recursively from c:\ and excludes "C:\Documents and Settings" and all of it's sub folders.
My colleagues and I have been trying many different approches to this like this:
foreach ($file in $(Get-ChildItem c:\ -Recurse | where { $_.PSIsContainer -and $_.Name -ne 'Documents and Settings' } | gci)) { $file.fullname }
but each time we run it, it displays Documents and Settings each time anyway, even though we have excluded it. Obviously, -exclude would have been ideal if it worked in PS v2, but the help file accurately indicates that it does not work properly in this cmdlet.
The final result is that we would use this script as the basis to set permissions on all folders that it returned, and therefore would not impact any folders in C:\Documents and Settings. Any help would be appreciated.
|
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
Simon
 New Member Posts:4

 |
| 09 Sep 2010 06:23 PM |
|
Thanks very much Shay, that looks really good. So much easier than what I was thinking I had to do. I love how simple PowerShell can be... Just wish I knew how to do it.
|
|
|
|
|
teresap989
 New Member Posts:1

 |
| 10 Sep 2010 06:52 PM |
|
Thanks you for the post, sjc073>hi __________________ [url=http://moviesonlineworld.com]watch free movies online[/url] |
|
|
|
|
BustedFlush
 New Member Posts:97

 |
| 16 Feb 2011 09:03 AM |
|
Sorry to drag this thread back from the depths, but there's one thing I'm still confused about....
I noticed Shay suggested '^C:\\Documents and Settings' as the match criteria, and I didn't follow the logic.
I tried what I would have used: -notmatch "C:\Documents and Settings". That did not work.
But adding another \ to the C:\ does work (ie. "C:\\Documents and Settings") DOES work.
What's going on here? Does single quotes matter? Is the ^ some sort of regular expression indicator? Why dual slashes?
Any help appreciated.
|
|
|
|
|
PoSherLife
 Basic Member Posts:364

 |
|
BustedFlush
 New Member Posts:97

 |
| 16 Feb 2011 10:22 AM |
|
OK, that makes sense - at least as much sense as Regex usually do, but is there an advantage of using a Regex at all in this case, as opposed to the literal value? |
|
|
|
|
PoSherLife
 Basic Member Posts:364

 |
|
BustedFlush
 New Member Posts:97

 |
| 16 Feb 2011 11:00 AM |
|
Ahh, OK - cool, didn'trealize that. Thanks! |
|
|
|
|