I’m trying to create a custom powershell provider in c# that allows you to manage items (in a folder type directory) users should be able to cd to –> files/folder and be able to see child items etc and manipulate that.
My issue is I can always travel to the root directory however as soon as I try and set my location to myAcme:/any_path_here_of_valid_item it will error as seen below. This is strange as I can get-item on this path. Am I missunderstanding something here or is it not possible to set your location to the location of the item (I’m trying to set my location to that item to get its child items)
PS my****:\> cd myAcme:/
PS myAcme:\> get-item /files/folders/****
<Removed so you don' get hit by a wall of text but this displays the items info fine>
PS myAcme:\> cd myAcme:/files/folders/****
Set-Location : Cannot find path 'myAcme:/files/folders/****' because it does not exist.
At line:1 char:3
+ cd <<<< myAcme:/files/folders/****
+ CategoryInfo : ObjectNotFound: (myAcme:/files/folders/****:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
I’m not going display any code here for now as I’m pretty sure it’s more likely I’m miss understanding the concept of containercmdletprovider
EDIT
I forgot to add in the debugger ItemExists is returning true when I do the command cd myAcme:/files/folders/**
ContainerCmdletProvideris only for simple providers that have no subfolders. Examples of such providers are thefunction,envandvariabledrives in PowerShell. Such providers do not supportset-location,get-location(cd) or the notion of nested paths. Everything should be in the root, and must be a leaf node (e.g. file.)If you want to use a tree structure, you must inherit from
NavigationCmdletProvider. You might find it easier to develop if you use my scripted provider framework which allows you to prototype providers very fast using regular PowerShell script. There are some examples and simple docs, as well as the download, up on http://psprovider.codeplex.com/Good luck!