Core Skills Level: Intermediate Chapter 7: One Way to Explore Every Store
Providers and drives
A provider is an adapter that makes a data store look like a drive. Once you see a store as a drive, the file commands you already know start working on it.
Lesson 1 of 1 in Chapter 7: One Way to Explore Every Store. Previous step in this path: Import a module and build a custom module. 3 learning objectives, 12 examples, and a knowledge check.
Start: what you will learn
A provider is an adapter that makes a data store look like a drive. Once you see a store as a drive, the file commands you already know start working on it.
Learning objectives
- Explain a provider in plain words
- List drives with Get-PSDrive
- Move between drives and list their contents
Concept in simple words
What it is: a provider is a helper program that makes a data store look like a drive, with items arranged in a hierarchy, like folders and files. A drive is a named entry point into one of those stores, such as C: for files, HKLM: for part of the registry, or Env: for environment variables. An environment variable is a named setting that programs can read, such as a path or a temporary folder location. A hierarchy simply means items inside items, like a folder inside a folder, or a registry key inside a registry key.
Why it works
Why it exists, and what problem it solves: before providers, each store needed its own tool and its own way of thinking. Files had one tool, registry settings had another, and variables had another. That meant you had to learn the same basic jobs many times, once for each store. Providers solve that by giving every store the same shape, so one set of moves, list, move, and look inside, works in many stores. You learn less, and you can explore more, because the moves stay familiar even when the store changes.
Think of it like this
Think of it like this: imagine several different buildings, a file store, a settings store, and a variables store, all fitted with the same kind of doors and corridors. A provider is the fitting that makes each building navigable in the same way. A drive is the front door you walk through, and once inside, you look around with the same simple moves. The rooms are still different, a file room is not a registry room, but you do not need a new map for every building.
What PowerShell is doing behind the command: when you type a provider path, PowerShell does not go straight to a disk. It asks the provider for that store to translate your request into something that store understands. For C:, the FileSystem provider talks to the disk. For HKLM:, the Registry provider talks to the registry. For Env:, the Environment provider talks to the list of environment variables in your session. You type the same kind of path, and the provider does the translation work for you. That translation is why the same command can return files in one place and settings in another.
Containers and leaves, in plain words: many provider items are containers, which means they can hold child items inside them. A folder is a container, and a registry key acts like a container too. Other items are leaves, which means they do not hold children. A file is a leaf in the file store. When you run Get-ChildItem, you are asking for the child items inside a container. If you run it on a leaf, there are no children to list, so you get a different result, and that difference is normal, not an error in your thinking.
The built in providers, one by one: FileSystem gives you disks and folders, with drives like C:. Registry gives you the registry, with HKLM: for the local machine part and HKCU: for the current user part. Environment gives you environment variables, with Env:. Variable gives you PowerShell variables in your session, with Variable:. Alias gives you command aliases, with Alias:. Function gives you functions, with Function:. Certificate gives you certificate stores, with Cert:. You do not need to memorise this list today, but it helps to see that each drive name is just a short label for one store.
Provider, drive, and path, kept apart: the provider is the helper, the drive is the named door, and the path is the route after the door. In HKLM:\SOFTWARE, HKLM: is the drive, and \SOFTWARE is the path inside that drive. In Env:, there is no deeper path, because environment variables sit in one flat list. In C:\Windows, C: is the drive, and \Windows is the folder inside it. If you mix these three ideas up, paths start to look confusing, so name each part when you read a path out loud.
The colon matters: a provider drive name in a path ends with a colon, such as Env: or HKLM:. That colon is the signal that says, this is a drive, not a folder name. When you ask Get-PSDrive for one drive by name, you use the bare name with no colon, such as Get-PSDrive Env. When you move into a drive or list a drive path, you use the colon, such as Set-Location Env: or Get-ChildItem Env:. Swapping those two forms is one of the most common small slips, and the error message is your clue to check the colon first.
How it works, step by step
How it works, step by step: first, list your drives with Get-PSDrive, and note the provider behind each drive. Next, check where you are with Get-Location, so you know your starting point. Then either move into a drive with Set-Location, such as Set-Location Env:, or its shorter alias cd, or peek at a drive without moving by giving Get-ChildItem a full drive path. Then list the items there with Get-ChildItem, exactly as you would list files. Finally, move back when you are done, with Set-Location C: or with Pop-Location if you used Push-Location, which remembers where you were. This order, look, check, peek or move, list, return, keeps you from acting in the wrong store.
Reading Get-PSDrive output, column by column: Name is the short drive name, such as C or Env. Provider tells you which helper owns that drive, such as FileSystem or Environment. Root tells you where the drive starts, such as C:\ for files, or HKEY_LOCAL_MACHINE for HKLM:. Used and Free are useful for disk drives, because they describe disk space. For other drives, those columns are often blank, and that is expected, because a list of variables has no disk space to report. Do not treat a blank Used or Free column as a broken drive.
Let us walk through listing drives: in Get-PSDrive | Select-Object Name, Provider, Root, Get-PSDrive first returns one object for every drive in your session. The pipe sends those objects to Select-Object. Select-Object keeps only the three properties you named, Name, Provider, and Root, and drops the rest, so the table is easy to read. If you remove the Select-Object part, you will see more columns, including space columns for disk drives. If you change Root to CurrentLocation, you will see where you last were on each drive instead of where the drive starts. Look for the Provider column first, because it tells you what kind of store each drive really is.
Let us walk through listing providers: in Get-PSProvider | Select-Object Name, Drives, Get-PSProvider lists the helpers themselves, not the drives. The Name column is the helper name, such as Registry or Environment. The Drives column lists the drives that helper owns, such as HKLM and HKCU for Registry, or Env for Environment. This view answers a different question from Get-PSDrive. Get-PSDrive asks, what doors do I have. Get-PSProvider asks, what helpers do I have, and which doors does each helper own. If a drive puzzles you, check its provider here.
Let us walk through filtering to disk drives only: in Get-PSDrive -PSProvider FileSystem, -PSProvider is a filter that keeps only drives owned by the FileSystem provider. That means registry, environment, variable, and other provider drives drop out of the result, and you see disk drives only. Change FileSystem to Registry, and you will see HKLM and HKCU only. Change it to Environment, and you will see Env only. If you spell the provider name wrong, you will get no rows or an error, so copy the provider name exactly from the Get-PSDrive output.
Let us walk through asking for one drive: in Get-PSDrive Env, Env is the drive name, given with no colon and no path. PowerShell returns just that one drive object, so you can check its provider and root without reading a long table. Change Env to C, and you will see the file drive instead. Add a colon by mistake, as in Get-PSDrive Env:, and PowerShell will not find a drive with that name, because the name itself has no colon in it. That contrast is worth practising until it feels automatic.
What Get-Location tells you, and why you check it: Get-Location shows your current location, including the drive you are on. After Set-Location Env:, your prompt and your Get-Location result should both show Env:. After Set-Location C:, they should show C: again. Always run Get-Location before a command that changes something, because a relative path means something different on each drive. A command that is safe on C: can be dangerous on HKLM: if you forgot that you moved.
Let us walk through an example: in Set-Location Env: followed by Get-ChildItem | Select-Object Name -First 3, the first line moves you into the environment drive. Get-ChildItem then lists environment variables as items, just as it lists files in a folder. Select-Object keeps only Name, and -First 3 keeps the first three rows. Look at the names in the output, and check that they are settings, not files, which shows the same command working on a different store. If you change -First 3 to -First 1, you will see only the first row. If you remove Select-Object, you will also see the Value column, which is often the more useful column for environment variables.
The Value column, and why Name alone can mislead: environment variables are pairs, a name and a value. Path is a name, and the list of folders in that value is what programs actually use. TEMP is a name, and the folder path in its value is where temporary files go. If you select only Name, you learn what settings exist, but not what they are set to. That is fine for a first look, but for real checking, keep both Name and Value, as in Select-Object Name, Value. The same lesson applies everywhere, so always ask, which property answers my real question, before you trim the output.
Let us walk through peeking without moving: in Get-ChildItem -Path Env: | Select-Object Name -First 3, -Path tells Get-ChildItem exactly where to look, so you do not need to move first. Your current location stays where it was, and the listing still comes from Env:. This is the safer habit when you only want a quick look, because you cannot forget to move back afterwards. Change -Path Env: to -Path C:, and you will list files instead, with no move at all. If you leave -Path out entirely, Get-ChildItem lists your current location, whatever drive that happens to be, so a missing -Path is a common cause of surprising results.
The registry, in plain words, and why care is needed: the registry is a settings store for Windows and for programs, organised as keys inside keys, much like folders inside folders. HKLM: is the local machine part, which affects the whole computer, and HKCU: is the current user part, which affects only your account. Listing registry keys is safe and read only, because listing changes nothing. Changing or deleting registry items is a different matter, because a wrong change can break a program or a setting, and undoing it is not always as simple as restoring a deleted file. So in this chapter, list first, think second, and change only with a clear reason and a preview.
Let us walk through pushing into the registry and popping back: in Push-Location HKLM:\SOFTWARE followed by Get-ChildItem | Select-Object Name -First 3 and then Pop-Location, Push-Location first remembers where you were, by putting your current location on a stack, and then moves you to HKLM:\SOFTWARE. Get-ChildItem lists the items there, and Select-Object keeps only Name, with -First 3 keeping the first three rows. Pop-Location then takes your remembered location off the stack and moves you back there, so you do not get lost in a different drive. If you change SOFTWARE to a deeper key, you will list that deeper key instead. If you forget Pop-Location, you will stay in the registry, and your next relative command will run there, so always close a push with a pop.
The stack, like a pile of plates: a location stack works last in, first out, like a pile of plates. The last location you push is the first location you pop back to. If you push twice, first to one place and then to another, the first pop returns you to the second pushed place, and the second pop returns you to your start. You can peek at the stack with Get-Location -Stack, which lists the remembered locations without changing where you are. If you pop with nothing on the stack, PowerShell will report an error, and that error is useful, because it tells you there is nothing left to return to.
Let us walk through listing the registry without moving: in Get-ChildItem -Path HKLM:\SOFTWARE | Select-Object Name -First 2, -Path does all the work, and your location never changes. This is the read only way to explore the registry, and it is the best first step when you are learning. Compare it with the push example above, and notice that the listing part is the same, only the moving part is different. If you change -Path to HKLM:\SOFTWARE\Microsoft, you will go one level deeper without moving. If you change -First 2 to a larger number, you will see more subkeys, but the first rows will stay the same.
Variables, functions, and aliases as drives: Set-Location Variable: moves you into the list of PowerShell variables in your session, and Get-ChildItem there lists variable names, just as Get-ChildItem in Env: lists setting names. Set-Location Alias: and Get-ChildItem Alias: do the same for command aliases, and Function: does the same for functions. These drives are wonderful for browsing and learning, because listing them changes nothing. Do not edit or delete items here casually, because variables, aliases, and functions are part of how your session works, and removing one can break the command that depends on it.
Let us walk through variables and aliases: in Set-Location Variable: followed by Get-ChildItem | Select-Object Name -First 5, the move puts you in the Variable drive, the listing shows variable names, and -First 5 keeps the first five rows. Change -First 5 to -First 3, and you will see fewer rows, with the same first rows. In Get-ChildItem Alias: | Select-Object Name -First 3, there is no move at all, because Alias: is a full drive path on its own. Look at the names, and notice how short alias names sit beside the longer command names they stand for, which is exactly what an alias is for. Your own variable list will differ from the illustrative output, because it depends on your session, so compare the shape of the output, not every single name.
Returning home, with proof: in Set-Location C: -PassThru, Set-Location moves you back to the C: drive, and -PassThru tells PowerShell to show you the new location, even though Set-Location normally shows nothing. That shown location is your proof that the move worked, so read it before you run the next command. Without -PassThru, the move still works, but you see no output, and silence can hide a failed move or a typo. Use -PassThru whenever you want visible confirmation, and use Get-Location on its own whenever you want a plain check with no move.
Making your own drive, and cleaning it up: New-PSDrive creates a new drive in your session, and it needs three pieces, -Name for the new drive name, -PSProvider for the helper, and -Root for where the drive starts. For a FileSystem drive, -Root is a folder path, and that folder must already exist. A new drive made this way is temporary by default, which means it lives only in your session, and it disappears when the session ends. It also does not appear in File Explorer, because it is known only to PowerShell. Remove-PSDrive -Name with the bare drive name removes it again, and cleaning up keeps your drive list tidy for the next task.
Let us walk through a temporary shortcut drive: in New-PSDrive -Name ShortWin -PSProvider FileSystem -Root C:\Windows, -Name ShortWin gives the new drive its short name, -PSProvider FileSystem says it is a file drive, and -Root C:\Windows says it starts at that folder. Then Get-ChildItem ShortWin: | Select-Object Name -First 3 lists the first three items in that folder through the new drive, without you ever typing the long folder path again. Then Remove-PSDrive -Name ShortWin removes the temporary drive, using the bare name with no colon. If you change -Root to a folder that does not exist, the creation will fail, so check the folder first. If you skip the removal, the drive will stay until your session ends, which is untidy but not harmful for a temporary drive. The exact first rows in the illustrative output depend on folder contents, so yours may differ, and that difference is normal.
Same command, different objects: Get-ChildItem returns objects, not plain text, and the properties on those objects depend on the store. Files have properties like Name, Length, and LastWriteTime. Environment items have Name and Value. Registry keys have Name and other registry properties. That is why a column that makes sense on C: may be empty or missing on Env:, and that is not a bug. Before you select a property, check what properties the listing actually shows, and select from those. Some parameters also behave differently by provider, so a parameter that works well for files may not be available or may act differently in another store, and the help for that provider is the place to check.
Relative paths, and going up one level: once you are inside a drive, a plain name means a child of your current location in that drive, and .. means go up one level, just as in folders. From HKLM:\SOFTWARE\Microsoft, Set-Location .. would move you back to HKLM:\SOFTWARE. From Env:, there is no deeper level to go up from, because Env: is a flat list, so .. has no deeper meaning there. A path that starts with a drive name, such as HKLM:\SOFTWARE, is absolute for that drive, and it works from anywhere. A path with no drive name is relative, and it depends entirely on where you are, which is why checking Get-Location matters so much.
When to use it
When to use it, and when not to: use providers when you want to browse a store with familiar commands, or when a task naturally fits a drive, such as checking environment variables or registry keys. Do not treat every store like files, because some changes are harder to undo than deleting a file. Registry changes in particular deserve a preview and a careful check before you change anything. Listing is the safe default in this chapter, and changing is a separate decision that needs its own reason, its own check, and its own preview.
Safety rules for every provider: first, list before you change, so you know what is really there. Second, use a full drive path when you only want to look, so you do not move by accident. Third, check Get-Location before any command that sets, creates, or removes something. Fourth, when a changing command offers a preview option, use it first, and read the preview as if it were the real change, because in many cases it soon will be. Fifth, never change registry items or environment values on a shared or important computer just to practise, because the effects can reach beyond your session. Read only exploring is safe, and it is enough for this chapter.
Common confusions, explained slowly: a drive is not a disk, even though C: looks like one, because Env: and Variable: have no disk behind them at all. A provider is not a drive, because one provider can own more than one drive, as Registry owns both HKLM: and HKCU:. A listing is not a change, because Get-ChildItem and Get-PSDrive only read, while Set-Item, New-Item, and Remove-Item change things. A temporary drive is not a permanent mapping, because it ends with your session unless you deliberately make a persistent mapping. Keeping those four distinctions clear will prevent most provider mistakes before they happen.
Worked examples
Read each example in order. Each one explains its parts, then shows what to look for in the output.
Syntax
Get-PSDrive | Set-Location <Drive>:\<Path>Example 1
Lists drives, their providers, and their roots, so you can see every store you can navigate. Read the Provider column first, because it tells you what kind of store each drive is.
Get-PSDrive | Select-Object Name, Provider, RootIllustrative output: Name Provider Root ---- -------- ---- C FileSystem C:\ HKLM Registry HKEY_LOCAL_MACHINE
Example 2
Lists the providers themselves, with the drives each provider owns. Use this when a drive puzzles you, and you want to know which helper owns it.
Get-PSProvider | Select-Object Name, DrivesIllustrative output: Name Drives ---- ------ Registry {HKLM, HKCU} Environment {Env} FileSystem {C}
Example 3
Keeps only FileSystem drives, so registry and other provider drives drop out. Change FileSystem to Registry to see HKLM and HKCU only.
Get-PSDrive -PSProvider FileSystemIllustrative output: Name Provider Root ---- -------- ---- C FileSystem C:\
Example 4
Asks for one drive by its bare name, with no colon. The colon belongs in a path, not in a drive name for this command.
Get-PSDrive EnvIllustrative output: Name Provider Root ---- -------- ---- Env Environment
Example 5
Moves into the environment drive, then lists environment variables as items. Select-Object keeps only Name, and -First 3 keeps the first three rows. Add Value to the selection when you want to see what each setting is set to.
Set-Location Env:
Get-ChildItem | Select-Object Name -First 3Illustrative output: Name ---- Path TEMP
Example 6
Lists environment variables without moving, because -Path gives the full drive path. Your current location stays where it was, so there is nothing to move back from.
Get-ChildItem -Path Env: | Select-Object Name -First 3Illustrative output: Name ---- Path TEMP TMP
Example 7
Push-Location HKLM:\SOFTWARE moves into the registry drive at the SOFTWARE key, and remembers where you came from. Get-ChildItem lists the items there, and Select-Object keeps only Name, with -First 3 keeping the first three rows. Pop-Location returns you to the place you were before, so you do not get lost in a different drive.
Push-Location HKLM:\SOFTWARE
Get-ChildItem | Select-Object Name -First 3
Pop-LocationIllustrative output: Name ---- Microsoft Policies
Example 8
Lists registry subkeys without moving, which is the safest first step for exploring the registry. Change the path to go deeper, without changing your location.
Get-ChildItem -Path HKLM:\SOFTWARE | Select-Object Name -First 2Illustrative output: Name ---- Microsoft Policies
Example 9
Moves into the Variable drive, then lists variable names. Change -First 5 to a smaller number to see fewer rows, with the same first rows.
Set-Location Variable:
Get-ChildItem | Select-Object Name -First 5Illustrative output: Name ---- ConfirmPreference DebugPreference ErrorActionPreference FormatEnumerationLimit MaximumHistoryCount
Example 10
Lists aliases without moving, because Alias: is a full drive path on its own. Alias names are short, and they stand for longer command names.
Get-ChildItem Alias: | Select-Object Name -First 3Illustrative output: Name ---- cd cls dir
Example 11
Moves back to C: and shows the new location as proof. Without -PassThru, the move still works, but you see no output.
Set-Location C: -PassThruIllustrative output: Path ---- C:\
Example 12
Creates a temporary file drive called ShortWin for C:\Windows, lists through it, then removes it. The folder in -Root must already exist, and the temporary drive ends with your session even if you skip the removal.
New-PSDrive -Name ShortWin -PSProvider FileSystem -Root C:\Windows
Get-ChildItem ShortWin: | Select-Object Name -First 3
Remove-PSDrive -Name ShortWinIllustrative output: Name ---- System32 Fonts Web
Nothing on this page executes PowerShell code. The outputs above are illustrative only.
Common mistakes and troubleshooting
Read these before you try the examples, so you can spot the same problems in your own work.
- Assuming Get-ChildItem only works on files. It works on any provider drive.
- Deleting a registry item with Remove-Item as casually as a file. Registry changes are harder to undo, so preview first.
- Using Set-Location to move into a drive, and then running a command that assumes you are still on C:, so it reads or changes something in the wrong store. Always check your current location before a command that changes things.
- Swapping the colon forms: using Get-PSDrive Env: with a colon, or Set-Location Env with no colon. Get-PSDrive takes the bare drive name, while a path to move into or list needs the colon.
- Running Get-ChildItem with no path and assuming it lists C:. It lists your current location, whatever drive that happens to be, so check Get-Location first if the result surprises you.
- Calling Pop-Location with nothing on the stack, or popping twice after one push. The first pop returns you to your start, and a second pop has nothing left to return to, so close every push with exactly one pop.
- Selecting only Name for environment variables, then wondering what each setting is set to. Name tells you what exists, Value tells you what it is set to, so keep both when you need the real value.
- Assuming a property that exists for files, such as Length, will also exist for environment items or registry keys. Properties depend on the store, so select only from the properties the listing actually shows.
- Creating a New-PSDrive with a name that already exists, or with a -Root folder that does not exist, and then wondering why the creation failed. Check Get-PSDrive for the name first, and check that the root folder exists first.
- Expecting a temporary New-PSDrive to appear in File Explorer, or to still be there in a new session. A temporary drive is known only to PowerShell in that session, so remove it when you are done, and do not rely on it later.
- Changing an environment value such as Path, or a registry value, without noting the old value first. If the change breaks something, you will need that old value to put things back, so list and note it before you change anything.
Knowledge check
Knowledge check
What is a PowerShell drive?
Pick one answer. Feedback appears right away, and you can try again.
Remember this and next step
Remember this: a provider makes a store look like a drive, a drive is your entry point, and Get-ChildItem lists what is inside. Start by listing drives and providers, peek with a full drive path when you only want to look, check Get-Location before you change anything, and always return to where you started, with Push-Location and Pop-Location, or with Set-Location C: and -PassThru for proof. The same moves work in files, in the registry, in environment variables, and in other stores, and that reuse is the skill this chapter teaches. Explore widely with read only commands, change nothing in the registry or in environment values without a clear reason and a preview, and you will stay in control.
Next step: Functions