Re: [MSH] get-childitem - quick way to find/sort on number children

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
>


.



Relevant Pages

  • Re: NTE_BAD_KEYSET seems to depend on certificate(Win98, Internet expl
    ... CERT_KEY_PROV_INFO_PROP_ID to get the container name and the provider ... The exact same code and certificate work fine in Windows 2K. ... >> pwszContainerName is associated with a certifcate of keylength ...
    (microsoft.public.platformsdk.security)
  • Re: PFXImportCertStore
    ... has the pwszProvName equaling "Microsoft Base Cryptographic Provider v1.0" ... for the container created by PFXImportCertStore for a p12 file housing a 1024 ... I would have expected it to use the enhanced CSP... ...
    (microsoft.public.platformsdk.security)
  • Re: Passwortlaenge
    ... die einem Provider oder einer Bank in die ... ziehen, die zum Schutz besagter Container eingesetzt werden. ...
    (de.comp.security.misc)
  • Re: User objects cannot be created in the specified container
    ... Groups are not container types. ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... point my provider to the root of AD every thing works fine. ... nested container under root I am getting the following error. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: a snapin with some commandlets to run MSH commands in the back
    ... processes, tasks, etc) as a new type of provider in V2. ... Microsoft Command Shell Development ... also you indicated passing in everything not as a string, ... main MSH runspace and my backgroundpipeline runspaces. ...
    (microsoft.public.windows.server.scripting)