Question: I have a database with over 10TB of data and need to organize the data. I am doing this by using Powershell to output only the folders to a text file and then import that to excel for further processing. I ONLY want the folders and subfolders of say the Z drive for instance. I do not want any files. I am encountering a problem when I try to exclude certain folders and all the subfolders within it.

Say for example the name of the folders and their contents I want to exclude are 'BackScatter' and 'MicroData'.
I am using this script:

```
dir -recurse -Exclude "Backscatter","MicroData" | Where-Object { $_.PSIsContainer } | ForEach-Object { $_.FullName } > ZDrive.txt

```

I do not get an error it just simply doesnt exclude those folders when it does its recursive.

Also I was wondering if I could just exclude subfolders within 'Backscatter' and not the entire folder. I did do much searching on the site but I am so new I cant comprehend any of the scripts that answer the question.

Answer: 
[Get-Help Get-ChildItem -Full](http://technet.microsoft.com/library/hh847897.aspx)

I'm using PS 3.0, it appears that there is `-File` and `-Directory` switch that you can use instead of the `? {$_.psiscontainer}`. When working with large data use [Foreach-Object `%`](http://blogs.technet.com/b/heyscriptingguy/archive/2009/07/22/hey-scripting-guy-how-can-i-speed-up-my-windows-powershell-scripts.aspx) it's faster then Where-Object. As for the `-Exclude` not working, I'm not sure. You can always use [regex](http://www.regular-expressions.info/reference.html) and the `-match` operator.

```
Get-ChildItem $path -r -Directory | % {if($_.name -notmatch 'BackScatter|MicroData'){$_.fullname}}

```
Try this:

```
$excludes = @("BackScatter", "MicroData")

dir -recurse | ? {
  $_.PSIsContainer -and $excludes -notcontains $_.Name
} | % { $_.FullName } > ZDrive.txt

```