Powershell : Providers


As the name suggests the ‘Providers‘ provide access to data and components that would not otherwise be easily accessible at the command line. The data is presented in a consistent format that resembles a file system drive.

The data exposed by Providers appears in a drive like a file system drive, and you access the data in a path like you would on a hard disk drive. You can use any of the built-in cmdlets that the provider supports to manage the data in the provider drive. And, you can use custom cmdlets that are designed especially for the data.

BUILT-IN PROVIDERS : 

Windows PowerShell includes a set of built-in providers that you can use to access the different types of data stores.

To view the providers you can use the cmdlet Get-PSProviders in powershell.

pro

What each of these Providers mean? 

Alias : Windows PowerShell aliases
Cert : certificates for digital signatures
Env : Windows environment variables
File System : File system drives, directories, and files (C: , D: )
Function : Windows PowerShell functions (Cls, cd\, cd..)
Registry : Windows registry (HKLM \ HKCU)
Variable : Windows PowerShell variables (PWD)
WSMan : WS-Management configuration information

HOW TO VIEW PROVIDER DATA : 

You can use the Get-PSDrive cmdlet.
For example, to get all the properties of the Function: drive, type:

get-psdrive Function | format-list *

You can view and move through the data in a provider drive just as
you would on a file system drive.

To view the contents of a provider drive, use the

Get-Item or Get-ChildItem cmdlets

Type the drive name followed by a colon (:). For example, to
view the contents of the Alias: drive, type:

get-item alias:

You can view and manage the data in any drive from another drive by including the drive name in the path.

For example, to view the HKLM\Software registry key in the HKLM: drive from another drive, type:

get-childitem hklm:\software

To open the drive, use the Set-Location cmdlet or legacy change directory cmd (cd).
Remember the colon when you specify the drive path.

For example, to change your location to the root directory of the Cert: drive, type:

set-location Cert: or cd Cert:

Then, to view the contents of the Cert: drive, type:

get-childitem or gci (Alias of Get-Childitem)

HIERARCHICAL DATA OF PROVIDERS :

You can move through a provider drive just as you would a hard disk drive.
If the data is arranged in a hierarchy of items within items, use a backslash (\) to indicate a child item. Use the following format:

drive:\location\child-location\…

For example, to change your location to the HKLM\Software registry key, type a Set-Location command, such as:

set-location HKLM:\software or cd HKLM\Software\Microsoft\

UTILITY OF PROVIDERS:

I want to check the version of an installed software on my machine through registry key, how would I do that with powerhsell? Solution is the Registry provider of powershell, we can access it just like a file system drive and retrieve the data as desired. see the example how I retrieved the version of Silverlight sing the registry provider.

pro

Once you have understanding of Powershell providers you can easily use these data stores to manipulate the Registry Keys, File System, Environment Variables etc as per your needs.

Happy Learning ! 🙂

Advertisements

One thought on “Powershell : Providers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s