Chapter 19. Working with the File System

Windows PowerShell provides cmdlets to allow you to work effectively with drives, folders, and files on the file system. Windows PowerShell supports identification of drives using the get-psdrive cmdlet and exploration of files and folders using the get-childitem cmdlet. You can also create new drives, folders, and files. There is also a group of cmdlets that allow you to read and write content to and from text files.

Access to folders and files using Windows PowerShell is supported by the FileSystem provider. Additional command shell providers provide access to the HKLM (HKey_Local_Machine) and HKCU (HKey_Current_User) hives in the registry as well as drives for aliases, certificates, environment variables, functions, and variables. The command shell providers are in the Microsoft.Management.Automation.Core namespace.

If you want to find all providers supported on your system use the command:

get-psprovider

or, to find information about each drive and its associated provider, use this command:

get-PSdrive -Name * |
format-list

All drives on the local system are listed, as you can see in the part of the results shown in Figure 19-1.

Figure 19.1. Figure 19-1

The default information displayed includes the command shell provider relating to each drive. The value of the get-psdrive cmdlet's Name parameter is the wildcard *, which matches all ...

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.