PowerShell Providers

PowerShell providers abstract different resources in order to provide a common unified interface. Providers enable you to work with different resources as you would when working with the FileSystem. We can list the installed providers that are currently active on the system using the Get-PSDrive Cmdlet.

1
Get-PsDrive | Select Name, Provider, Root | Sort Provider | Format-Table -AutoSize

Above we use the Get-PsDrive CmdLet to list all of the active providers sorted by provider name.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Name     Provider                                  Root              
----     --------                                  ----              
Alias    Microsoft.PowerShell.Core\Alias                             
Env      Microsoft.PowerShell.Core\Environment                       
E        Microsoft.PowerShell.Core\FileSystem      E:\               
D        Microsoft.PowerShell.Core\FileSystem      D:\               
C        Microsoft.PowerShell.Core\FileSystem      C:\               
Function Microsoft.PowerShell.Core\Function                          
HKLM     Microsoft.PowerShell.Core\Registry        HKEY_LOCAL_MACHINE
HKCU     Microsoft.PowerShell.Core\Registry        HKEY_CURRENT_USER 
Variable Microsoft.PowerShell.Core\Variable                          
cert     Microsoft.PowerShell.Security\Certificate \                 
WSMan    Microsoft.WSMan.Management\WSMan

As an example of how providers work we can use the same interface for working with the File System and Registry Providers.

1
2
Set-Location C:\
Get-ChildItem

The above command will change directory to the root of the c: drive. It will then list the contents of the root directory. We can make the above command less verbose by using the Aliases for the above cmdlets.

1
2
cd C:\
dir

We can access the registry in the same way.

1
2
Set-Location HKLM:
Get-ChildItem

Conclusion

In this tutorial we introduced Powershell Providers and looked at some examples.