3.3. Namespaces as Drives

In PowerShell several data stores are exposed as drives. When you work with files and folders, you expect to see a drive as the container. In Windows PowerShell the registry, aliases, certificates, environment variables, functions, and variables are all exposed to you as drives. In other words, you can use the same cmdlets to work on items in the file system and the registry, aliases, certificates, functions, and environment variables.

Each of the data stores exposed by PowerShell as a drive is underpinned by a command shell provider. A command shell provider maps underlying data structures so that you can work with the data as if it were stored in folders and files. To display the providers available on your system, use this command:

get-psdrive |
group-object Provider |
format-list Name, Count

Figure 3-11 shows the providers available on one Windows XP system. Notice that the FileSystem provider supports several drives.

Figure 3.11. Figure 3-11

The get-psdrive cmdlet retrieves all drives defined on your system. In the second step of the pipeline, the group-object cmdlet groups objects passed to it by the first step of the pipeline according to the command shell provider. The final step of the pipeline formats the groups as a list, with the name of each group and the count in each displayed.

An alternative approach is to use the get-psprovider cmdlet: ...

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.