PowerShell tutorial 6

PowerShell providers are .NET programs that provide a data access layer between powershell and the data. Providers abstract data so that the same mechanisms within powershell can access the various data stores. A number of built-in providers are included with powershell.

To view a list use the get-psprovider cmdlet;

get-psprovider | select name

Here is a list of the built-in powershell providers.

  • alias – powershell built in and user defined aliases
  • certificate – windows digital signature certificates
  • environment – windows environment variables
  • filesystem – windows file system drives, folders, and files
  • function – powershell functions
  • registry – windows registry
  • variable – powershell variables

Custom providers can be developed to access other types of data stores and you can then install those providers and access the data the same way.

Providers reveal data through one or more powershell drives. the File-system provider reveals file-system data that have a direct relationship to Windows drives such as c: . You can use;

get-psdrive : sort provider, name

to view a list of powershell drives. This statement sorts the results by provider then by name so that the providers are grouped. You can also use get-psdrive to obtain information about a specific drive. The following example retrieves data about the function drive:

get-psdrive function | format-list

as you can see this statement returns information about the name of the provider and a description of the drive.

get-psdrive -psprovider registry

this statement returns information about the drives associated with the registry provider.

cd Env: changes the working location to the Env drive

You can access any drive type from any other drive type.

dir HKCU:

Env is still the working drive but now we’ve pulled results from the HKCU (hkey current user) drive. You can also change to any drive type from any other drive type. For example

cd HKCU: softwaremicrosoftoffice

this illustrates that not only can we change drives but we can specify folders within that drive or for that matter the registry, file system or other data store. By using powershell drives we can hop from location to location without special steps.

Get-itemproperty `HKLM:SoftwareMicrosoftASP.NET

this example retrieves a list of properties and values about the registry key HKey Local MachineSoftwareMicrosoftASP.NET. The results also include powershell specific information such as the name of the powershell drive and provider.

New-Item ` HKLM:softwaremicrosofttestkey1

This command creates the Testkey1 key in Hkey local machine softwaremicrosoft. After the key is created you can then use the New-Item property cmdlet to add properties to that key.

new-itemproperty `

HKLM:softwaremicrosofttestkey1 `
-name testproperty – propertytype string `
-value “test value”

when you run this statement, the property “test value” is added to Hkey local machinesoftwaremicrosofttestkey1. You can also take other actions.

Rename-Item `
HKLM:softwaremicrosofttestkey1 `

In this example we first identifiy the orginal key and then provide a new name for that key. You can also use the remove-item cmdlet to remove a registry key.

Remove-item `

As I mentioned PowerShell also has the ability to create custom drives. To creat a custom drive use the new-psdrive cmdlet.

new-psdrive -name ps `
-psprovider filesystem -root $pshome

This statement identifies the new drive, then provider, and lastly the root. After you have created your drive, you can use it the same way you use any other built in drive. For example cd ps: changes the working location to the ps drive. To test whether you’re working in the correct folder run the get-childitem cmdlet.

Powershell also includes the Remove-PSDrive cmdlet which lets you remove user-defined drives. To use the cmdlet you must be in a working location other then the one you want to delete.

cd c:; Remove-PSDrive ps

5 thoughts on “PowerShell tutorial 6
  1. Hi,

    I have implemented a custom provider, but, i m not able to implement the tab completion for this provider.

    Could any one help me there?

    Thanks in advance!


    • try ” format (drive letter):” so for example if you want to format a drive named d: the simplest form of that command would be “format d:” . Do be careful though, its not generally a good plan to format your OS drive (usually c:) unless you are doing so from the windows installation disk.

Leave a Reply