How can I list all the Titles for Namespace?

This topic contains 4 replies, has 4 voices, and was last updated by  Richard Siddaway 4 years, 2 months ago.

  • Author
    Posts
  • #8587

    Guy Thomas
    Participant

    Situation
    I created a Shell Application type of ComObject
    Get-Member reveals it has a ‘Namespace’ method.
    Example

    $Shell = New-Object -ComObject Shell.Application
    $Shell.NameSpace

    I can make a few luck guesses for instance (0x5)

    $Shell.NameSpace(0x5)

    Title ‘My Documents’.

    Question: How can I list all the Titles for Namespace?

  • #8591

    Warren Frame
    Participant

    Looks like it takes an integer.  You could do something like this and work with the objects as desired (e.g. select -expandproperty Title, work with the self property, etc).  For example:

    
    $shell = New-Object -ComObject Shell.application
    
    1..60 | %{ $shell.namespace($_) | ?{$_.title} | select -expandproperty Title }

    Another example:

    foreach($i in $(1..60)){
    
    $shell.namespace($i) | ?{$_.title} | select @{l="index";e={$i}}, Title, @{l="Path";e={$_.Self.Path} }
    
    }
  • #8592

    Don Jones
    Keymaster

    And, to directly answer your question, there is no programmatic way of listing the integers that it will accept. You'll have to guess, or do as suggested and see what exists on your system. That's an old COM object and doesn't provide a lot of discoverability.

  • #8596

    Guy Thomas
    Participant

    Dear Cookie Monster

    Brilliant, stunning, just what I wanted. Naturally, it worked just as you indicated, thank you.

  • #8604

    Richard Siddaway
    Moderator

    I did document most of the common ones in the appendix of PowerShell in Practice

You must be logged in to reply to this topic.