Help

All of the functions in psprovider template modules represent exactly the same methods you'd have to implement in C# to create a provider. If you want to learn what these methods do and how to implement them correctly, follow the "writing a windows powershell provider" tutorials and information on MSDN. Some good places to start:

MSDN References for Providers

Windows PowerShell Provider Overview
This topic describes what Windows PowerShell providers are and how they work.

Windows PowerShell Provider Concepts
This section describes the concepts that you should be familiar with when designing or writing providers.

Provider Samples
This section provides samples of providers.

Samples and Templates

Container Sample

This is a working sample for the ContainerScriptProvider provider. It lets you navigate around a Hashtable.

# assumes DLL is in current directory
ipmo .\PSProviderFramework.dll

# root parameter is mandatory, but you don't have to use it in your module script
new-psdrive ps containerscriptprovider -root / -moduleinfo $(new-module -name test {

 $data = @{
  a = "a" | select foo,bar
  b = "b" | select foo,bar
  c = "c" | select foo,bar
  d = "d" | select foo,bar
 }

 function getitem($path) {
  $psprovider.writeverbose("getitem '$path'")
  
        if ($path) {
            
   if ($data[$path]) {
    $psprovider.writeitemobject($data[$path], $path, $false)
   }
  } else {
   # root
   $psprovider.writeitemobject($data.values, "/", $true)
  }
 }

 function itemexists($path) {
  if ($path) {
   $psprovider.writewarning("item exists $path")
   $data.containskey($path)
  } else {
   # root always exists
   $true
  }
 }

 function getchildnames($path, $returnContainers) {
  
  $psprovider.writeverbose("getchildnames '$path' $returnContainers")
  
  if ($path) {
   if ($data[$path]) {
                $psprovider.writeitemobject($path, $path, $false)
            }
  } else {
   $data.keys | % { $psprovider.writeitemobject($_, [string]$_, $false) }
  }
 }

 function getchilditems($path, $recurse) {
  $psprovider.writeverbose("getchildnames '$path' $returnContainers")
  if ($path) {
   $psprovider.writeitemobject($data[$path], $_, $false)
  } else {
   $data.keys | % {
    $psprovider.writeitemobject($data[$_], $_, $false)
   }
  }
 }
})

Tree Template

This does not contain an implementation - it's just a skeleton that you'll have to fill out yourself.

function ClearItem {
    [cmdletbinding()]
    param(
		[string]$path
    )

    $psprovider.writeverbose("ClearItem")
    # ...
}
function CopyItem {
    [cmdletbinding()]
    param(
		[string]$path, 
		[string]$copyPath, 
		[bool]$recurse
    )

    $psprovider.writeverbose("CopyItem")
    # ...
}
function GetChildItems {
    [cmdletbinding()]
    param(
		[string]$path, 
		[bool]$recurse
    )

    $psprovider.writeverbose("GetChildItems")
    # ...
}
function GetChildNames {
    [cmdletbinding()]
    param(
		[string]$path, 
		[Management.Automation.ReturnContainers]$returnContainers
    )

    $psprovider.writeverbose("GetChildNames")
    # ...
}
function GetItem {
    [cmdletbinding()]
    param(
		[string]$path
    )

    $psprovider.writeverbose("GetItem")
    # ...
}
function HasChildItems {
    [cmdletbinding()]
	[outputtype('bool')]
    param(
		[string]$path
    )

    $psprovider.writeverbose("HasChildItems")
    # ...
}
function InvokeDefaultAction {
    [cmdletbinding()]
    param(
		[string]$path
    )

    $psprovider.writeverbose("InvokeDefaultAction")
    # ...
}
function IsItemContainer {
    [cmdletbinding()]
	[outputtype('bool')]
    param(
		[string]$path
    )

    $psprovider.writeverbose("IsItemContainer")
    # ...
}
function IsValidPath {
    [cmdletbinding()]
	[outputtype('bool')]
    param(
		[string]$path
    )

    $psprovider.writeverbose("IsValidPath")
    # ...
}
function ItemExists {
    [cmdletbinding()]
	[outputtype('bool')]
    param(
		[string]$path
    )

    $psprovider.writeverbose("ItemExists")
    # ...
}
function MoveItem {
    [cmdletbinding()]
    param(
		[string]$path, 
		[string]$destination
    )

    $psprovider.writeverbose("MoveItem")
    # ...
}
function NewItem {
    [cmdletbinding()]
    param(
		[string]$path, 
		[string]$itemTypeName, 
		[Object]$newItemValue
    )

    $psprovider.writeverbose("NewItem")
    # ...
}
function RemoveItem {
    [cmdletbinding()]
    param(
		[string]$path, 
		[bool]$recurse
    )

    $psprovider.writeverbose("RemoveItem")
    # ...
}
function RenameItem {
    [cmdletbinding()]
    param(
		[string]$path, 
		[string]$newName
    )

    $psprovider.writeverbose("RenameItem")
    # ...
}
function SetItem {
    [cmdletbinding()]
    param(
		[string]$path, 
		[Object]$value
    )

    $psprovider.writeverbose("SetItem")
    # ...
}

Last edited Jul 13, 2012 at 3:32 PM by oisin, version 8

Comments

No comments yet.