PowerShell providers
A PowerShell provider, or PSProvider, is an adapter. It’s designed to take some kind of data storage and make it look like a disk drive. 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. You can see a list of installed providers right within the shell:
- get-psprovider
Notice that each provider has different capabilities. This is important, because it
affects the ways in which you can use each provider. These are some of the common
capabilities you’ll see:
- ShouldProcess—Means the provider supports the use of the -WhatIf and -Confirm parameters, enabling you to “test” certain actions before committing to them.
- Filter—Means the provider supports the -Filter parameter on the cmdlets that manipulate providers’ content.
- Credentials—Means the provider permits you to specify alternate credentials when connecting to data stores. There’s a -credential parameter for this.
- Transactions—Means the provider supports the use of transactions, which allows you to use the provider to make several changes, and then either roll back or commit those changes as a single unit.
PowerShell Drives “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).
You use a provider to create a PSDrive. A PSDrive uses a single provider to connect to some actual data storage. You’re essentially creating a drive mapping, much like you might have in Windows Explorer, but a PSDrive, thanks to the providers, is able to connect to much more than disks. Run the following command to see a list of currently connected drives:
- get-psdrive
You can change to these drives by typing the below. Windows environment variables are visible as a PS drive called Env:
- set-location -path env:
- Try typing dir
- You can also type it all in one as get-child-item env: or dir env:
The PowerShell Environment Provider
The Environment Providers are 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
Leave a Reply