View Single Post
Old 08-28-2007   #3 (permalink)
Keith Hill [MVP]


 
 

Re: get-child item question from a newbie

"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:#rTB#Qd6HHA.3264@xxxxxx
Quote:

> powersheller@xxxxxx wrote:
>
> Welcome!
>
> get-item
> *|foreach-object{if($_.psiscontainer){$_}}|foreach-object{set-location
> $_;$pwd}
As you'll soon discover with PowerShell, there are usually quite a few ways
to accomplish a task:

get-childitem -recurse | where {$_.PSIsContainer} | set-location -passthru |
foreach {du $_.providerpath}

or the shortened (aliased) version:

gci -r | ?{$_.PSIsContainer} | set-location -pas | %{du.exe $_.providerpath}

The thing to note here is that you should consider using "get-member" at the
various stages of the pipeline to see what kind of object you get. For
instance:

gci -r | gm

will show you DirectoryInfo and FileInfo objects.

gci -r | ?{$_.PSIsContainer} | gm

will show just DirectoryInfo objects because the FileInfo objects get
filtered out.

gci -r | ?{$_.PSIsContainer} | set-location -pas | gm

shows that set-location -passthru converts the DirectoryInfo object into a
PathInfo object with a property called ProviderPath that you will want to
pass to legacy apps. If you want to see the property values of these
PathInfo objects try this:

gci -r | ?{$_.PSIsContainer} | set-location -pas | format-list *

--
Keith

My System SpecsSystem Spec