PowerShell Providers

In this tutorial we will go though PowerShell Providers. We will see which are the default providers in Windows PowerShell and how we are able to import and remove providers from a session. Microsoft describes PowerShell Providers as below:

PowerShell providers are Microsoft .NET Framework-based programs that make the data in a specialized data store available in PowerShell so that you can view and manage it.

You can access the data in a provider the same way like accessing files in your data drive. Each provider supports all Windows PowerShell core set of commands that are included by default. Those commands are provided in “PowerShell Core Commands” tutorial. A provider may have also custom commands only for the specific provider that you can use with it. Also some parameters may be available on existing commands that you are allowed to use them with the specific provider only.

Below is a list of the built-in providers in Windows PowerShell.

Built-in Providers

Alias Drive: Alias: Data Store: PowerShell Aliases

Certificate Drive: Cert: Data Store: x509 Certificates for Digital Signatures

Environment Drive: Env: Data Store: Windows Environment Variables

FileSystem Drive: (*) Data Store: File System Drives, Directories and Files

Function Drive: Function: Data Store: PowerShell Functions

Registry Drive: HKLM: and HKCU: Data Store: Windows Registry

Variable Drive: Variable: Data Store: PowerShell Variables

WSMan Drive: WSMan: Data Store: WS-Management Configuration Information



During a session you are able to create your own provider. To create a provider you need to

[adinserter name=”In Article”]

Find the loaded PowerShell Providers

In order to see the current providers that are loaded in your current session you need to used the following command:

Code:

Get-PSProvider

Output:

Adding and Removing Providers

Adding a Provider

The providers, except of the built-in ones which are loaded by default, are added / installed in Windows PowerShell when you import a module in the current session. In the example below you can see that I import ActiveDirectory module into my session and when I check the loaded providers, I can see the provider for Active Directory.

Code:

Get-PSProvider Import-Module ActiveDirectory Get-PSProvider

Output:

[adinserter name=”In Article”]

Removing a Provider

If we want to remove a provider from our current session, there are two ways to do it. The first one is to remove the module from the current session. If you remove the module then the provider will be removed also. You can remove the module by using the below command.

Code:

Get-PSProvider Remove-Module ActiveDirectory Get-PSProvider

Output:

The other way to remove a provider is to remove the drive associated with. Basically, this method will remove the drive but will not affect the data within the drive. It will make the drive unavailable. You can do so by using the following command.

Code:

Get-PSPsrovider Remove-PSDrive -Name "AD" Get-PSProvider

Output:

[adinserter name=”In Article”]

Provider Home

You are able to set Home for the providers. The only provider that has a default value for Home is FileSystem. All other providers have nothing as a default value but you can set it yourself. To provide a home directory for a provider you need to use the Home property of the provide. The below examples are showing the change of Home for FileSystem and Registry providers.

Code:

Get-PSProvider | Format-Table Name, Home (Get-PSProvider FileSystem).Home = 'C:\' Get-PSProvider | Format-Table Name, Home (Get-PSProvider Registry).Home = 'HKLM:\' Get-PSProvider | Format-Table Name, Home

Output:

[adinserter name=”In Article”]

Provider related cmdlets

Below I am providing you once again the related cmdlets for PowerShell Providers. More information about those commands you can find in the section below with related links.

ChildItems cmdlets Get-ChildItem

Content cmdlets Add-Content Clear-Content Get-Content Set-Content

Item cmdlets Clear-Item Copy-Item Get-Item Invoke-Item Move-Item New-Item Remove-Item Rename-Item Set-Item

ItemProperty cmdlets Clear-ItemProperty Copy-ItemProperty Get-ItemProperty Move-ItemProperty New-ItemProperty Remove-ItemProperty Rename-ItemProperty Set-ItemProperty

Location cmdlets Get-Location Pop-Location Push-Location Set-Location

Path cmdlets Join-Path Convert-Path Split-Path Resolve-Path Test-Path

PSDrive cmdlets Get-PSDrive New-PSDrive Remove-PSDrive

PSProvider cmdlets Get-PSProvider



I hope the tutorial about PowerShell Providers is helpful.

Please let me know your comments and thoughts.

You feedback is appreciated.

[adinserter name=”In Article”]

Related Links:

[adinserter name=”Matched-Content”]