Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8063127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:55:02+00:00 2026-06-05T10:55:02+00:00

I’ve implemented a simple PowerShell NavigationCmdletProvider . For those who don’t know, this means

  • 0

I’ve implemented a simple PowerShell NavigationCmdletProvider.

For those who don’t know, this means I can create a snap-in with a cmdlet which is effectively a virtual filesystem drive; this drive can be mounted and navigated into from PowerShell like any normal folder. Each action against the drive (e.g., check if a path points to a valid item, get a list of names of child items in a folder, etc.) is mapped to a method of the .NET class inherited from the NavigationCmdletProvider class.

I’m facing a problem with tab-completion, and would like to find a solution. I’ve found that tab-completion gives incorrect results when using relative paths. For absolute paths, it works fine.

For those who don’t know, tab completion for a NavigationCmdletProvider works through PowerShell calling the GetChildNames method, which is overridden from the NavigationCmdletProvider class.

–Demonstration of the issue–

Assume I have a provider, ‘TEST’, with the following folder hierarchy:

TEST::child1
TEST::child1\child1a
TEST::child1\child1b
TEST::child2
TEST::child2\child2a
TEST::child2\child2b
TEST::child3
TEST::child3\child3a
TEST::child3\child3b

Absolute paths:

If I type “dir TEST::child1\” and press tab a few times, it gives me the expected results:

> dir TEST::child1\child1a
> dir TEST::child1\child1b

Relative paths:

First, I navigate to “TEST::child1”:

> cd TEST::child1

Then, if I type “dirspace” and press tab a few times, it gives me incorrect results:

> dir .\child1\child1a
> dir .\child1\child1b

I expect to see these instead:

> dir .\child1a
> dir .\child1b

Is this a bug in PowerShell, or am I doing something wrong?

Here’s the complete, self-contained code for the provider:

[CmdletProvider("TEST", ProviderCapabilities.None)]
public class MyTestProvider : NavigationCmdletProvider
{
    private Node m_Root;
    private void ConstructTestHierarchy()
    {
        //
        // Create the nodes
        //
        Node root = new Node("");
            Node child1 = new Node("child1");
                Node child1a = new Node("child1a");
                Node child1b = new Node("child1b");
            Node child2 = new Node("child2");
                Node child2a = new Node("child2a");
                Node child2b = new Node("child2b");
            Node child3 = new Node("child3");
                Node child3a = new Node("child3a");
                Node child3b = new Node("child3b");

        //
        // Construct node hierarchy
        //
        m_Root = root;
            root.AddChild(child1);
                child1.AddChild(child1a);
                child1.AddChild(child1b);
            root.AddChild(child2);
                child2.AddChild(child2a);
                child2.AddChild(child2b);
            root.AddChild(child3);
                child3.AddChild(child3a);
                child3.AddChild(child3b);
    }

    public MyTestProvider()
    {
        ConstructTestHierarchy();
    }

    protected override bool IsValidPath(string path)
    {
        return m_Root.ItemExistsAtPath(path);
    }

    protected override bool ItemExists(string path)
    {
        return m_Root.ItemExistsAtPath(path);
    }

    protected override void GetChildNames(string path, ReturnContainers returnContainers)
    {
        var children = m_Root.GetItemAtPath(path).Children;
        foreach (var child in children)
        {
            WriteItemObject(child.Name, child.Name, true);
        }
    }
    protected override bool IsItemContainer(string path)
    {
        return true;
    }
    protected override void GetChildItems(string path, bool recurse)
    {
        var children = m_Root.GetItemAtPath(path).Children;
        foreach (var child in children)
        {
            WriteItemObject(child.Name, child.Name, true);
        }
    }
}

/// <summary>
/// This is a node used to represent a folder inside a PowerShell provider
/// </summary>
public class Node
{
    private string m_Name;
    private List<Node> m_Children;

    public string Name { get { return m_Name; } }
    public ICollection<Node> Children { get { return m_Children; } }

    public Node(string name)
    {
        m_Name = name;
        m_Children = new List<Node>();
    }

    /// <summary>
    /// Adds a node to this node's list of children
    /// </summary>
    public void AddChild(Node node)
    {
        m_Children.Add(node);
    }
    /// <summary>
    /// Test whether a string matches a wildcard string ('*' must be at end of wildcardstring)
    /// </summary>
    private bool WildcardMatch(string basestring, string wildcardstring)
    {
        //
        // If wildcardstring has no *, just do a string comparison
        //
        if (!wildcardstring.Contains('*'))
        {
            return String.Equals(basestring, wildcardstring);
        }
        else
        {
            //
            // If wildcardstring is really just '*', then any name works
            //
            if (String.Equals(wildcardstring, "*"))
                return true;

            //
            // Given the wildcardstring "abc*", we just need to test if basestring starts with "abc"
            //
            string leftOfAsterisk = wildcardstring.Split(new char[] { '*' })[0];
            return basestring.StartsWith(leftOfAsterisk);

        }
    }

    /// <summary>
    /// Recursively check if "child1\child2\child3" exists
    /// </summary>
    public bool ItemExistsAtPath(string path)
    {
        //
        // If path is self, return self
        //
        if (String.Equals(path, "")) return true;

        //
        // If path has no slashes, test if it matches the child name
        //
        if(!path.Contains(@"\"))
        {
            //
            // See if any children have this name
            //
            foreach (var child in m_Children)
            {
                if (WildcardMatch(child.Name, path))
                    return true;
            }
            return false;
        }
        else
        {
            //
            // Split the path
            //
            string[] pathChunks = path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

            //
            // Take out the first chunk; this is the child we're going to search
            //
            string nextChild = pathChunks[0];

            //
            // Combine the rest of the path; this is the path we're going to provide to the child
            //
            string nextPath = String.Join(@"\", pathChunks.Skip(1).ToArray());

            //
            // Recurse into child
            //
            foreach (var child in m_Children)
            {
                if (String.Equals(child.Name, nextChild))
                    return child.ItemExistsAtPath(nextPath);
            }
            return false;
        }
    }

    /// <summary>
    /// Recursively fetch "child1\child2\child3" 
    /// </summary>
    public Node GetItemAtPath(string path)
    {
        //
        // If path is self, return self
        //
        if (String.Equals(path, "")) return this;

        //
        // If path has no slashes, test if it matches the child name
        //
        if (!path.Contains(@"\"))
        {
            //
            // See if any children have this name
            //
            foreach (var child in m_Children)
            {
                if (WildcardMatch(child.Name, path))
                    return child;
            }
            throw new ApplicationException("Child doesn't exist!");
        }
        else
        {
            //
            // Split the path
            //
            string[] pathChunks = path.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);

            //
            // Take out the first chunk; this is the child we're going to search
            //
            string nextChild = pathChunks[0];

            //
            // Combine the rest of the path; this is the path we're going to provide to the child
            //
            string nextPath = String.Join(@"\", pathChunks.Skip(1).ToArray());

            //
            // Recurse into child
            //
            foreach (var child in m_Children)
            {
                if (String.Equals(child.Name, nextChild))
                    return child.GetItemAtPath(nextPath);
            }
            throw new ApplicationException("Child doesn't exist!");
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:55:04+00:00Added an answer on June 5, 2026 at 10:55 am

    I’ve listed this as a PowerShell provider bug in Microsoft Connect: Issue with relative path tab-completion (via Get-ChildNames) for NavigationCmdletProvider

    If anyone can reproduce this, please visit the link and say so, because Microsoft probably won’t look into this if only one person is reporting it.

    It looks like this is fixed in PowerShell 3.0. I don’t know why Microsoft doesn’t want to fix this in older versions, it’s not something any code could possibly depend on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.