Beyond the file system

The home of my variables

Let's start with an example:

PS C:\> $var="Find me!"
PS C:\> Set-Location Variable:
PS Variable:\> Get-ChildItem
 
Name                           Value
----                           -----
...
scriptdir                      C:\Users\bru\Documents\WindowsPowerShell\scripts
ShellId                        Microsoft.PowerShell
StackTrace
true                           True
var                            Find me!
VerbosePreference              SilentlyContinue
WarningPreference              Continue
...

I have set a variable, changed current working directory to a drive called Variable and read the content of the drive. There we see the variable, I have set before. So you can access your variables just as if they were located on a drive. What makes this possible behind the scenes is called a Powershell Content Provider. Content Providers let you navigate data stores as if they were mounted drives. There is an open API, so you can write your own Powershell Content Provider using .NET.

Now let's see, what content providers are present in a default installation of Powershell:

> Get-PSProvider
 
Name                 Capabilities                                      Drives
----                 ------------                                      ------
WSMan                Credentials                                       {WSMan}
Alias                ShouldProcess                                     {Alias}
Environment          ShouldProcess                                     {Env}
FileSystem           Filter, ShouldProcess                             {C, D, A, Z}
Function             ShouldProcess                                     {Function}
Registry             ShouldProcess, Transactions                       {HKLM, HKCU}
Variable             ShouldProcess                                     {Variable}
Certificate          ShouldProcess                                     {cert}

So there are content providers for webservice configuration, shell aliases, environment variables, file systems, defined Powershell functions, Windows Registry, Powershell variables and certificates. If you want to know, what (logical) drives are served by content providers, you should use the command Get-PSDrive.

Powershell Content Providers not only let you browse the content, but also change it. Just like with the file system content provider you can delete content, rename content or create content.

There is a lot more

There is a lot more to talk about Powershell, like Scripting, working with COM, WMI and .NET, extending Powershell with modules, and so on.

Get in touch