Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

get-childitem and exclude complete folder

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-15-2007   #1 (permalink)
Thomas Kofler
Guest


 

get-childitem and exclude complete folder

Hi,

I try to report on some folders and must exclude some of them, but

Get-ChildItem -path "C:\" -recurse -exclude "DFSReports"

does not exclude the folder C:\DFSReports.

Is there a workaround or am i missing something,

Thanks a lot.

My System SpecsSystem Spec
Old 11-15-2007   #2 (permalink)
Kuma
Guest


 

Re: get-childitem and exclude complete folder

On Nov 16, 12:06 am, Thomas Kofler
<ThomasKof...@xxxxxx> wrote:
Quote:

> Hi,
>
> I try to report on some folders and must exclude some of them, but
>
> Get-ChildItem -path "C:\" -recurse -exclude "DFSReports"
>
> does not exclude the folder C:\DFSReports.
>
> Is there a workaround or am i missing something,
>
> Thanks a lot.
Get-Help Get-ChildItem -Parameter Exclude

Returns the following (Note the "Doesn't work properly" part)

-exclude <string[]>
Omits the specified items. The value of this parameter qualifies
the Path parameter. Enter a path element or patter
n, such as "*.txt". Wildcards are permitted.

This parameter does not work properly in this cmdlet.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? true

You could try this.

Get-Childitem -Path "C:" | Where {$_.PSisContainer -eq $false}
Get-Childitem -Path "C:" | Where {$_.PSisContainer -eq $true} | Where
{$_.name -ne "DFSReports"} | ForEach {Get-Childitem -Path $_ -Recurse}

This gets you all of the items in all of the subdirectories under C:\
except "DFSReports".

Hope that helps a bit.
My System SpecsSystem Spec
Old 11-15-2007   #3 (permalink)
Marco Shaw [MVP]
Guest


 

Re: get-childitem and exclude complete folder

Thomas Kofler wrote:
Quote:

> Hi,
>
> I try to report on some folders and must exclude some of them, but
>
> Get-ChildItem -path "C:\" -recurse -exclude "DFSReports"
>
> does not exclude the folder C:\DFSReports.
>
> Is there a workaround or am i missing something,
>
> Thanks a lot.
I have v2 CTP and see this in the get-childitem help:

-exclude <string[]>
Omits the specified items. The value of this parameter
qualifies the Path parameter. Enter a path element or pa
ttern, such as "*.txt". Wildcards are permitted.

**This parameter does not work properly in this cmdlet.**

What were you looking to do? You could possibly pipe this to a
where-object or foreach-object cmdlet to drop the directories you don't
want.

Maco



--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 11-15-2007   #4 (permalink)
Damian Pinto
Guest


 

RE: get-childitem and exclude complete folder

Thomas,
I found that the problem is when is used C:\ with path, if you
try to use another path C:\Test this work. Sorry, I know that I gave a
solution, but another person gave a solution.

Regards


"Thomas Kofler" wrote:
Quote:

> Hi,
>
> I try to report on some folders and must exclude some of them, but
>
> Get-ChildItem -path "C:\" -recurse -exclude "DFSReports"
>
> does not exclude the folder C:\DFSReports.
>
> Is there a workaround or am i missing something,
>
> Thanks a lot.
My System SpecsSystem Spec
Old 11-15-2007   #5 (permalink)
Shay Levi
Guest


 

Re: get-childitem and exclude complete folder


Maybe this can help, its example #3 from the get-childitem help file (type:
(get-help get-childitem).examples.example[2])

-------------------------- EXAMPLE 3 --------------------------

C:\PS>get-childitem c:\windows\logs\* -include *.txt -exclude A*


This command lists the .txt files in the Logs subdirectory, except for those
whose names start with the letter A. It uses the wildcard
character (*) to indicate the contents of the Logs subdirectory, not the
directory container. Because the command does not include the
Recurse parameter, Get-Childitem does not include the content of directory
automatically; you need to specify it.


Try:

Get-ChildItem -path C:\* -exclude DFSReports -recurse



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com


Quote:

> Hi,
>
> I try to report on some folders and must exclude some of them, but
>
> Get-ChildItem -path "C:\" -recurse -exclude "DFSReports"
>
> does not exclude the folder C:\DFSReports.
>
> Is there a workaround or am i missing something,
>
> Thanks a lot.
>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
get-childitem -exclude bug bep PowerShell 7 03-11-2008 07:47 PM
Bug in Get-ChildItem -exclude loworbit@gmail.com PowerShell 4 12-19-2006 05:58 PM
RE: Exclude directories from Get-ChildItem? ~Clint PowerShell 0 11-29-2006 03:14 PM
RE: Exclude directories from Get-ChildItem? RichS PowerShell 0 11-29-2006 01:30 PM
Exclude directories from Get-ChildItem? ~Clint PowerShell 0 11-29-2006 12:47 PM


Update your Vista Drivers Update Your Vista Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008
Page generated in 0.26493 seconds with 10 queries