Re: [MSH] get-childitem - quick way to find/sort on number children
- From: "Jeff Jones [MSFT]" <jeffjon@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 17 Nov 2005 09:17:06 -0800
It depends on what the provider implementation returns. In the FileSystem
provider the returned object for a container is a DirectoryInfo object. It
has a method called GetFileSystemInfos() which returns an array of its
children. So if you know you are in the file system you can do:
MSH > get-childitem . | foreach { if ($_ -is [System.IO.DirectoryInfo]) {
$_.GetFileSystemInfos().Length } }
or if you are in the registry you can use the SubKeyCount property:
MSH > get-childitem . | foreach { if ($_ -is [Microsoft.Win32.RegistryKey])
{ $_.SubKeyCount } }
You could even put the type in a switch statement and handle all the ones
you know about. My solution below will work for any provider regardless of
the type of object it returns.
--
Jeff Jones [MSFT]
Microsoft Command Shell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"Keith Hill" <r_keith_hill@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ubQbuty6FHA.1188@xxxxxxxxxxxxxxxxxxxxxxx
> "Jeff Jones [MSFT]" <jeffjon@xxxxxxxxxxxxxxxxxxxx> wrote in message
> news:OL9CBws6FHA.1724@xxxxxxxxxxxxxxxxxxxxxxx
>> get-childitem . -recurse | group-object MshParentPath | sort-object Count
>
> I was kind of expecting an "Items" property for each MshContainer such
> that I could easily do a:
>
> get-childitem . | foreach { if ($_.MshIsContainer) { $_.Items.Count }}
>
> Most container objects expose their child item collections - at least in
> .NET they do.
>
> --
> Keith
>
.
- Follow-Ups:
- Re: [MSH] get-childitem - quick way to find/sort on number children
- From: Keith Hill
- Re: [MSH] get-childitem - quick way to find/sort on number children
- References:
- [MSH] get-childitem - quick way to find/sort on number children
- From: Keith Hill
- Re: [MSH] get-childitem - quick way to find/sort on number children
- From: Jeff Jones [MSFT]
- Re: [MSH] get-childitem - quick way to find/sort on number children
- From: Keith Hill
- [MSH] get-childitem - quick way to find/sort on number children
- Prev by Date: Re: [MSH] Why :: for static methods?
- Next by Date: Re: Create Users in WXP
- Previous by thread: Re: [MSH] get-childitem - quick way to find/sort on number children
- Next by thread: Re: [MSH] get-childitem - quick way to find/sort on number children
- Index(es):
Relevant Pages
|