PSDrive stands for PowerShell Drives through which you can access the data provided by the PowerShell providers.
You can Learn more about PowerShell Providers on https://geekeefy.wordpress.com/2015/04/06/powershell-providers/
You will come through following types of PowerShell drives:
- Windows logical drives on the computer, including drives mapped to network shares, or the File System Drives
- Drives exposed by Windows PowerShell providers, such as the Certificate:, Function:, and Alias: drives.
- PowerShell Registry providers, HKLM: and HKCU: drives that are exposed by the Windows
To veiw the list of powershell Drives available on you machine you can type
Like in the below image
These are the PowerShell Data providers exposed in a consitent format like our File Sytem.
PSDrives can be used in various ways to access data sources like Active Directory, registry keys and perform actions over them using powershell scripts and cmdlets.
EXAMPLE : On a machine I need to check a particular registry key very often, and every time I’ve to open registry Editor (Regedit) and drill down to that specifc registry hive (Suppose HKLM) and find the registry key. Using the PSDrive we can make it fast and make registry accessible like any file system Drive.
Here we’ll map the required registry hive location using New-PSDrive in our powershell console. Just type the below comamnd.
New-PSDrive -Name PowershellReg -PSProvider Registry -Root HKLM:\SOFTWARE\Microsoft\PowerShell\3\
To Access the newly created PSDrive ‘PowershellReg’, just by typing in
Please do not to forget the Colon just after the PSDrive name (‘ : ‘), otherwise you will get an error.
Now, Suppose you want to access any Registry value, let’s suppose Powershell version can be accessed like this .
Well, There are Lot more thing that can be achieved using PSDrives, Like you can aslo create new registry keys using the New-Item cmdlet.
And you can verify the same using the RegEdit.
One important point to note here is all your PSDrives are Non-Persistent and they disappear as soon your session is closed.
To make your session Persistent and to last it even if your session is closed, you can map the PSDrive to the Explorer window using a switch ‘ -Persist ‘ in your New-PSDrive Cmdlet like below –
New-PSDrive -Name 'P' -Description 'Powerhsell study Videos' -PSProvider FileSystem -Root '\\127.0.0.1\D$\Powershell\Vids' -Persist
New drive will be mapped to your Explorer.
QUICK TIP : Persist switch will force you to map drives for remote locations, but you can cheat the cmdlet 😉 by using the loopback IP address or your machine name if you want to map a drive locally.
Hope this was helpful, Happy learning ! 🙂