During my P2F talk at the PowerShell Summit NA 2014, I announced a project that would make creating a PowerShell Provider “stupid simple.” I happily present you the first iteration of this stupid simplicity in the form of the Simplex open source project.
The goal of Simplex is to remove any barrier between the operator and the items they would like to access as a PowerShell drive. Instead of focusing on C# types, interfaces, and cmdlet support, Simplex keeps you in script, using a simple domain-specific language (DSL) based on PowerShell to define a drive hierarchy. Here is an example of the DSL:
root { # the root folder of the drive
folder System { # a folder named System
script Processes -id Id { # a folder named Processes
get-process # that contains Process objects
}
script Errors -id Index { # a folder named Errors containing event log entries
get-eventLog -log application -entrytype error -newest 25
}
}
}
To mount this Simplex script as a PowerShell drive, you just need to use the Simplex module, like so:
import-module simplex;
new-psdrive -name s -psprovider simplex -root "c:\path\to\simplexscript.ps1"
Once the script it mounted, you can navigate the folders and script containers as if they were a filesystem:
PS C:\Windows\SysWOW64\WindowsPowerShell\v1.0> cd s:
PS s:\> dir
Container: Simplex\Simplex::C:\share\simplex.ps1
Type Name
---------- ---- ----
d+~< Folder System
PS s:\> cd system
PS s:\system> dir
Container: Simplex\Simplex::C:\share\simplex.ps1\system
Type Name
---------- ---- ----
d+~< Script Processes
d+~< Script Errors
PS s:\system> cd errors
PS s:\system\errors> dir
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
63846 Jul 31 09:05 Error Application Error 1000 ...
Simplex DSL
The Simplex DSL has three elements: root, folders, and scripts. Each element defines a container location on the drive. The root element defines the root of the drive and contains any number of script and folder elements.
root {
# any number of script and/or folder elements
}
Folders can also contain other folders and script elements, and folders must have a name.
folder <foldername> {
# any number of script and/or folder elements
}
Scripts are containers that use bits of PowerShell to supply the items they contain. Scripts elements also must have a name, and they can optionally specify an –idField parameter to identify a property to be used as the item’s child name.
script <foldername> [-idField <propertyname>] {
# PowerShell script to return objects from this folder
}
The DSL is “just PowerShell,” so you can actually do any PowerShell things you want to do. In this example, the DSL generates folders on demand based on the available performance counter sets:
root {
get-counter -list * | foreach {
$folderName = $_.CounterSetName;
script $folderName {
#...
}
}
}
When you mount and explore the drive, you’ll find a set of folders generated from the script:
PS g:\> dir
Container: Simplex\Simplex::C:\share\gen.ps1
Type Name
---------- ---- ----
d+~< Script RAS
d+~< Script WSMan Quota Statistics
d+~< Script Network QoS Policy
d+~< Script SMB Client Shares
d+~< Script SynchronizationNuma
d+~< Script Synchronization
d+~< Script Event Tracing for Win...
d+~< Script Thermal Zone Information
d+~< Script Processor Information
d+~< Script Event Tracing for Win...
d+~< Script FileSystem Disk Activity
# ...
So please check out the project, submit any issues/features you find/want. And as always, enjoy!