How can I list all the Titles for Namespace?

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 3 years, 9 months ago.

  • Author
    Posts
  • #8587
    Profile photo of Guy Thomas
    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
    Profile photo of Warren Frame
    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
    Profile photo of Don Jones
    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
    Profile photo of Guy Thomas
    Guy Thomas
    Participant

    Dear Cookie Monster

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

  • #8604
    Profile photo of Richard Siddaway
    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.