PowerShell Providers
PowerShell Tutorial 5: Windows PowerShell Providers
PowerShell Providers are .NET programs that allow us to work with data stores as if they were mounted drives. This simplifies accessing external data outside the PowerShell environment. For example, we can access the registry as if it were a file system. This translates to being able to use the same cmdlets as working with files and folders, which are shown in the table below.
| Cmdlet | Alias | Cmd Commands | Descritption |
|---|---|---|---|
| Get-Location | gl | pwd | Current Directory. |
| Set-Location | sl | cd, chdir | Change current directory. |
| Copy-Item | cpi | copy | Copy Files. |
| Remove-Item | ri | del | Removes a File or directory. |
| Move-Item | mi | move | Move a file. |
| Rename-Item | rni | rn | Rename a file. |
| New-Item | ni | n/a | Creates a new empty file or folder. |
| Clear-Item | cli | n/a | Clears the contents of a file. |
| Set-Item | si | n/a | Set the contents of a file. |
| Mkdir | n/a | md | Creates a new directory. |
| Get-Content | gc | type | Sends contents of a file to the output stream. |
| Set-Content | sc | n/a | Set the contents of a file. |
Take a look at the "about file" for more information:
SHORT DESCRIPTION
Windows PowerShell 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.
LONG DESCRIPTION
Windows PowerShell providers are .NET programs that make the data in a
specialized data store available in Windows PowerShell so that you can
easily view and manage it.
The data that a provider exposes appears in a drive, much like a hard drive.
You can use any of the built-in cmdlets that the provider supports to manage
the data in the provider drive, in addition to custom cmdlets that are
designed especially for the data.
The providers can also add "dynamic parameters" to the built-in cmdlets.
These are parameters that are available only when using the cmdlet with the
provider data.
A Provider is also called a "snap-in" which is a dynamic link library (.dll) built into PowerShell. A library is code that instructs PowerShell to preform an action when we execute a command. What this means is that we no longer have to write code, as we did in VBScript, to connect to the registry. The code is provided for us, simplifying our efforts. New and Custom Providers can be written, but this goes beyond the scope of this tutorial. The PowerShell Software Developers Kit provides documents should you wish to build your own Providers.
List Providers available in PowerShell
Using the "Get-PSProvider" cmdlet, we obtain a list of available PowerShell Providers:

Image 5.0
Here is the list of the PoweShell Providers available:
- Alias
- Environment
- FileSystem
- Function
- Registry
- Variable
- Certificate
PowerShell Drive "PSDrive"
We connect to PowerShell Providers by mounting the Providers PowerShell Drive(PSDrive). Most Providers have only one PSDrive, the exceptions are the FileSystem Provider(depends on the number of drives on the system) and the Registry Provider(HKLM and HKCU). Here is how to get a list of the available PowerShell Drives:

Image 5.1
The "Name" column reveals the PSDrives available on the system. We connect to each Provider using the PSDrive appended with a colon (:). Note: The example in image 5.1 shows the PSDrives without the (:) so you have to remember to use it when mounting a PSDrive.
Let's use this PowerShell training session to explore each of these providers.
The PowerShell Alias Provider
We discussed what an Alias "is" in PowerShell tutorial 3. The Alias Provider enables access to all the aliases in PowerShell. To mount a PSDrive we use the "Set-Location" cmdlet. In this example, we want to mount the "Alias:" PSDrive. Don't Forget the colon(:).

Image 5.2
As shown in image 5.2, we are now connected to the "Alias:" PSDrive. Just a quick note, PSDrives are only available in the PowerShell environment. You would not able to access the "Alias:" drive from a legacy windows command shell.
Now that we are mapped to the Alias: PSDrive we can use the same cmdlets as working with files and folders.
Eample 1. View a list of all aliases.

Image 5.2
Example 2. List the properties and methods.

Image 5.3
Example 3. Use the -Name parameter to list all Aliases that start with the letter "R". PowerShell supports the use of wild cards(*) to filter the results.

Image 5.4
Example 4. Building on example 3; instead of using a parameter to filter results, let's filter using the "name" property of the Alias object.

Image 5.5
We have worked a lot with aliases in a previous tutorial, so I'm going to move along to the next Provider. Feel free to use the commands listed in the table (above) and experiment with the Alias Provider.
The PowerShell Environment Provider
You may already be familiar with what the Environment Providers is, it is equivalent to running the "set" command in a windows CMD command shell. It provides a listing of all the environment variable defined on the system. Graphically, you can view the environment variables by going to System Properties -> Advanced Tab -> Click the "Environment Variables" button.

Image 5.6
Example 1. List Environment Variables
- Get list of available PowerShell Providers.
Get-PSDrive<enter> - Map PSDrive to Environment Provider.
Set-Location env:<enter> - Get listing of Environment Variables.
Get-ChildItem<enter>

Image 5.7
Example 2. Obtain the value of an Environment Variable
- Output the value of the "OS" variable.
Get-ChildItem OS<enter> - Output all properties for the "OS" variable.
Get-ChildItem OS | Format-List *<enter>
Example 3. Create a new Environment Variable
- Create a new variable using the "New-Item" cmdlet. Let's call the new variable "MyVariable" and give it a value of "This is my new variable." The Path argument will be a dot (.) meaning current location, which would be "env:"
New-Item -Path . -Name MyVariable -Value "This is my new variable"<enter>

Image 5.8
Use "Get-ChildItem" cmdlet to verify that the new variable exists.
Example 4. Renaming the Environment Variable
- Let's rename the "MyVariable" variable to "MyRenVar."
Rename-Item -Path env:MyVariable -NewName MyRenVar<enter> - Now use the "Get-ChildItem" cmdlet to verify the change.
Get-ChildItem<enter>
Example 5. Removing the Environment Variable
- To remove the "MyRenVar" variable we us the "Remove-Item" cmdlet.
Remove-Item MyRenVar<enter> - Use "Get-ChildItem" to verify the variable has been removed.
Get-ChildItem<enter>
PowerShell File System Provider
By default, the File System Provider is accessed when PowerShell is launched. The File System Provider allows you to create, retrieve, and remove files and folders. Also, the File System Provider allow you to modify files by either appending or overwritting data. This section of the PowerShell Providers tutorial explains how to do this.
Example 1. Listing Files and Directories
- Connect to the File System Provider. Close and re-launch PowerShell -or- connect to the File System Provider using the "Set-Location" cmdlet. Use the backslash (\) character to connect to the root of C: Drive
Set-Location C:\<enter> - List Files and Directories under the root of C: Drive.
Get-ChildItem<enter> - List Files and Directories including sub-direcories.
Get-ChildItem -Recurse<enter>
If your file system is large, the command in step 3 may take awhile. Use "Ctrl + C" to stop processing commands in PowerShell, just like you did in CMD command shell.
What is the "Mode" column? 5 bits of information you need to know.
- First entry is either "d" (indicates item is a directory) or "-" (indicates item is a file).
- The last 4 entries present the properties of a File and/or Directory (a r h s). "a" = archive bit is set, "r" = read only, "h" = hidden, and "s" = system. A "-" in any of these entries means the bit is not set.
Image 5.9
Note: By default, "Get-ChildItem" cmdlet or an Alias does not show hidden files and Directories. To show hidden files use the "-force" parameter.
As stated earlier in this PowerShell tutorial, Providers allow the use of the same cmdlets. Here is a second look at the cmdlet table, so that you don't have to scroll back to the top.
| Cmdlet | Alias | Cmd Commands | Descritption |
|---|---|---|---|
| Get-Location | gl | pwd | Current Directory. |
| Set-Location | sl | cd, chdir | Change current directory. |
| Copy-Item | cpi | copy | Copy Files. |
| Remove-Item | ri | del | Removes a File or directory. |
| Move-Item | mi | move | Move a file. |
| Rename-Item | rni | rn | Rename a file. |
| New-Item | ni | n/a | Creates a new empty file or folder. |
| Clear-Item | cli | n/a | Clears the contents of a file. |
| Set-Item | si | n/a | Set the contents of a file. |
| Mkdir | n/a | md | Creates a new directory. |
| Get-Content | gc | type | Sends contents of a file to the output stream. |
| Set-Content | sc | n/a | Set the contents of a file. |
Example 2. Using "Get-Location" Cmdlet
Use "Get-Location" to show current directory.
Using Alias and CMD Command.
Example 3. Creating files and Directories
Use "New-Item" cmdlet to create a New Directory.
A cool thing about PoweShell, it will assist you when you leave out required information. For example, let's say your creating the directory in the example above but you forget the -Type paramter.
New-Item -Path C:\NewFolder<enter>
PowerShell will prompt you for the missing parameter…
Type:
Continuing with the "New-Item" cmdlet, let's create a file in our new directory.
Example 4. Move NewFile to the root of "C:\" using "Move-Item" cmdlet
Verify file moved.
Example 5. Renaming Files and Directories
Let's rename the NewFile.txt to RenFile.txt.
Verify the file has been renamed.
Rename Directroy NewFolder to RenFolder.
Again, verify the change.
Example 6. Removing Files and Directories
in our last example of this PowerShell training section, let's remove the RenFolder and RenFile.txt. Just for fun, let's add the -confirm parameter so that PowerShell prompts us to confirm the action.
Press "Y" to confirm the deletion of the file and verify the files has been removed.
You should still see the RenFolder but the RenFile is no longer present. Now remove the directory.
Again, press "Y" to confirm and verify Directory has been removed.
There are other cmdlets such as "Clear-Item" and "Set-Item" that enable you to work with data within files. Use "Get-Help" on these cmdlets to read about how to use these cmdlets in the PowerShell FileSystem Provider. I personally like to use "Get-Content" to output a files contents to the screen and "Set-Content" to add information to a file.
PowerShell Function Provider
PowerShell has a set of Functions specified in the PowerShell engine. The PowerShell Function Provider allows us to access these functions using, hope this is starting to sound redundant, the same cmdlets as working with Files and Folders.
Not familiar with what a function is? A function allows you to make calls to a block of code. When scripting, if you notice that you are using the same code over and over (within the same script), you should consider creating a function. A function would reduce the amount of code and keep your scripts clean and readable. The examples in the section will help define a Function. Be aware that we are discussing Functions defined in PowerShell, not how to create PowerShell Functions. Creating your own Functions comes later in the PowerShell Scripting tutorials.
Example 1. Listing Functions
- Use "Set-Location" cmdlet and connect to the PowerShell Function Provider's PSDrive.
Set-Location Function:<enter> - You should be familiar with what cmdlet comes next…
Get-ChildItem<enter>

Image 5.10
Image 5.10 displays the Functions that are defined in PowerShell. "Name" is the name given to the function and the "Definition" is the code that runs when we call the name.
What does it mean to "call" a function? In PowerShell, we are only required to type a function name and the corresponding code will execute. For example, typing "set-Location C:" navigates to the root of C: drive. We can also navigate to the root of C: just by typing(calling) the "C:" function name. PowerShell runs the "Set-Location C:" code which places us at the root of C: drive. Let's take a look at another example.
Example 2. Viewing the Code of a PowerShell Function
- We are going to use the "Get-Content" cmdlet to view the code block of the Clear-Host Function.
Get-Content Clear-Host<enter>
Output:
$spaceType = [System.Management.Automation.Host.BufferCell]; $space = [Sys
tem.Activator]::CreateInstance($spaceType); $space.Character = ' '; $space
.ForegroundColor = $host.ui.rawui.ForegroundColor; $space.BackgroundColor
= $host.ui.rawui.BackgroundColor; $rectType = [System.Management.Automatio
n.Host.Rectangle]; $rect = [System.Activator]::CreateInstance($rectType);
$rect.Top = $rect.Bottom = $rect.Right = $rect.Left = -1; $Host.UI.RawUI.S
etBufferContents($rect, $space); $coordType = [System.Management.Automatio
n.Host.Coordinates]; $origin = [System.Activator]::CreateInstance($coordTy
pe); $Host.UI.RawUI.CursorPosition = $origin;
So my guess is that you would be more inclined to calling the "Clear-Host" function than actually typing the code required to clear the screen. Can you see how calling a function reduces the amount of code written in the script?
Before getting in too deep and making your head swim, I'm going to end this discussion about this Provider until we talk more about PowerShell Functions and Scripting. For now, let's move on to the coolest PowerShell Provider in the world!!!
The PowerShell Registry Provider
If you ever wanted to work with the registry with the same ease as working with the file system, your wish has come true. The Registry Provider allows us to connect to two PSDrives; HKCU (HKEY_CURRENT_USER) and HKLM (HKEY_LOCAL_MACHINE). With the Registry Provider we can:
- Navigate the registry.
- Search the registry.
- Create new registry keys.
- Delete registry keys.
- Add new values.
- Modify existing values.
- Manage ACLs (Access Control Lists).
Eample 1. Connect to the HKLM PSDrive and List Registry Keys.
- The two PSDrives we can connect to are HKLM and HKCU. Verify this by checking which PSDrives are available.
Get-PSDrive<enter>

Image 5.11 - Connect to HKLM PSProvider using the "Set-Location" cmdlet.
Set-Location HKLM:<enter> - We can also connect anywhere in the path. Let's connect to the SOFTWARE Key:
Set-Location HKLM:\Software<enter> - From the Software location let's list the keys available.
Get-ChildItem<enter>
Image 5.12
We're all familiar with the warnings of making changes to the Registry. Since I wish to only help and do no harm, I'm not going to provide examples of making registry changes. Just note that you can use the same cmdlets used when working with all PowerShell Providers.
| Cmdlet | Alias | Cmd Commands | Descritption |
|---|---|---|---|
| Get-Location | gl | pwd | Current Directory. |
| Set-Location | sl | cd, chdir | Change current directory. |
| Copy-Item | cpi | copy | Copy Files. |
| Remove-Item | ri | del | Removes a File or directory. |
| Move-Item | mi | move | Move a file. |
| Rename-Item | rni | rn | Rename a file. |
| New-Item | ni | n/a | Creates a new empty file or folder. |
| Clear-Item | cli | n/a | Clears the contents of a file. |
| Set-Item | si | n/a | Set the contents of a file. |
| Mkdir | n/a | md | Creates a new directory. |
| Get-Content | gc | type | Sends contents of a file to the output stream. |
| Set-Content | sc | n/a | Set the contents of a file. |
I will show you one very cool example of using the "Get-ChildItem" cmdlet to list installed Hot Fixes on a system:
Note: In the -Path parameter, quoting the path statement was required as there is a space between Windows and NT.
You should now see a list of "Hot Fixes" that have been installed on the system. Staying with the theme of this PowerShell tutorial, I'm going to use the "CD" alias to navigate to one of the "Hot Fix" keys. Choose any hot fix you wish to enumerate.
Next question should be… How do we enumerate the information inside the registry key? Simply use the "Get-ItemProperty" cmdlet.
I used the "." as we are currently working within the registry path location. You can also get the properties using the -Path parameter. Here's the example:
Now we see all the properties, how about just a specific property?
Create and Remove a New Registry Key and Property
First, Let's work from the root of SOFTWARE.
Create new registry Key and Default Property using "New-Item" cmdlet from the table.
Verify "Test" key exists
Verify the default property has the string value we created.
Next, Let's delete the new key using the "Remove-Item" cmdlet.
Verify the key has been removed.
Using the Registry Provider we are able to navigate, enumerate, create, and delete registry items just like files and folders.
Real-World Example: An associate of mine started working for a banking institution. We're talking multiple locations around the United States. His boss didn't like the naming convention for network printers as they provided no clue of printer type or location. His task was to create new print queues (with a new naming convention) and cut all the user over to the new print queues. Because he was dealing with multiple locations, it was impossible for a tech to be on-site to remap clients to the new print queues. Another requirement was to automate the process so that clients would not experience down time when printing. He told the boss… "No Problem."
I'm only going to describe what he did in pseudo code as it would take another tutorial to examine his script. Network Print Queues are stored in the registry as a UNC (\\PrintServer\PrinterName). He created a second print queue for each printer on all his print servers. Created a printer script which used an array to store the old printer names and their new counterparts. The script would change the registry setting from \\PrintServer\OldQueue to \\PrintServer\NewQueue while also preserving the default printer setting. He replicated the new script to all Domain Controllers in his environment and edited the company's logon script to call the printer script. When the printer script runs, it looks at the registry keys and if it finds reference to an old print queue name, it would edit that key with the new value. He allowed the script to run for a month or two to ensure that everyone using shared PCs would get the new print queues. After that time period, if he received calls from clients stating they could not connect to a new printer, he would just turn on the print script (uncomment it in the main logon script) and ask the client to re-logon the Domain.
This example shows just how powerful connecting the registry can be. Needless to say, his boss thought he was brilliant (which he is) an sent him off to Hawaii (ok - maybe not! But it is a nice thought).
The PowerShell Variable Provider
What is a variable? I like to think of a variable as a "little box" that is used to store information. The Variable Provider shows us which PowerShell and user defined variables are available. Again, we will be working with variables when scripting, so this is just an introduction.
Example 1. Connect to the PSDrive Variable: and Show a List of Available Variables
Connect to the PSDrive.
Use.. What Command to list variables?
Example 2. List the Information in the PSHome Variable
In PowerShell, variables are preceded by the dollar sign character ($). However, the list of variables in example 1. don't show a "$" sign. To view the information stored in the PSHome variable, just add the "$" before the variable name.
The $PSHome variable holds the information of the PowerShell installation path. Check out the information stored in other variables such as the $Profile and $Home variables.
Example 3. Create a User Defined Variable
There are a few ways to create variables. Since were talking about File System cmdlets used with providers, sticking with theme we would do the following:
You can also use the "Set-Variable" cmdlet to accomplish the same:
This last example is most commonly used when scripting. You will find yourself using this example more than the others:
Let's sort the listing of variables by name and verify our newly created variables exist.
Do you see MyVar, MyVar2, and MyVar3 user-defined variables?
Example 4. Remove Variables
Let's use the "Remove-Item" cmdlet to remove the variables we created:
Let's verify the variables have been removed:
By now your asking yourself, what is $_.Name? We can see that $_ must be a variable (all variables are noted by the dollar sign in PowerShell)… and it is. As defined, variables hold information. $_ is a special variable the holds the object piped from the "Get-ChildItem" cmdlet. The .Name is the Name Property of the object. I know your sick of me saying this but, we will explore script blocks in a later PowerShell tutorial.
One more PowerShell Provider to go…
The PowerShell Certificate Provider
Here is the last PowerShell Provider we need to cover. Using "Get-PSDrive" cmdlet we can see that we need to connect to the "cert" drive.
Example 1. Set Location to the Cert PSDrive and List all the Certificates on the System
This command truncates the "StoreNames" for good reason, there are a lot of entries. If you want a report of all certificates on a system may I suggest the following:
View results:

Image 5.13
Wow!!! we made it to the end of this PowerShell Training session. The basic concepts to take away from this tutorial are that PowerShell Providers allow us to use common cmdlets outside of the PowerShell environment. We only have to learn a few cmdlets, shortening the learning curve, to be affective working with:
- PowerShell Aliases
- Environment Variables
- Files and directories
- Functions
- The Registry
- Variables in PowerShell
- Certificates
Hope you enjoyed this tutorial, use the comment section for any questions or comments. See you in the next PowerShell Tutorial…
Email This Page



Akagi:
great tuto, thanks for the hard work
20 February 2008, 1:35 amPrashant Khopkar:
Best read! Enjoyed the simplicity, each example can be tried and explored in number of ways!
11 April 2008, 3:00 amEric:
There is no mkdir cmdlet…
18 May 2008, 1:11 pmFMoses:
Thanks for the great tutorials, much faster and more hands-on than scanning a book. I’m already seeing ways to use this at work.
Time for the next tutorial…
17 June 2008, 8:05 pmNorman:
I’ve come back here from the Active Directory tutorial to see what the square brackets notation means. Apparently “[ADSI]…” means to use the ADSI provider. This works, but I don’t understand how! Also, how can I find out what providers are available? There are no commands with noun=provider.
17 July 2008, 6:52 amNetGuyDave:
Thanks for taking the time to put together such a simple to understand tutorial. And I really want to say thank you for not assuming I know VB Script. Other tutorials keep saying “do it just like in VBScript except…..”, which doesn’t help me at all.
8 August 2008, 10:44 amHannibal:
Many thanks, Sir, I really get a lof from your tutorial.
29 September 2008, 12:42 pmJeppe:
Your tutorial is really fantastic. Really good examples
10 October 2008, 4:59 amShq:
Keep up the good work !!
12 November 2008, 7:47 pmKarl H:
Excellent guide, thanks for all the hard work. I appreciate it.
13 November 2008, 4:51 amKarl