19.6. Creating Custom Drives
If you are working on the command line, it can be time-consuming, tedious, and error prone to type something like
cd "c:\My Documents\Test Scripts\PowerShell Book"
time after time. Tab completion makes the process easier, but you still have to use the Tab key and arrows keys Windows PowerShell allows you to create a custom drive, let's call it book, so that you can simply type
cd book:
and you will be in the directory that you want to be in.
In this example, I will show you how to create a custom drive. First, you will use Windows PowerShell to create a directory structure. To do that, use these commands (assuming that your current location is in the root folder of drive C:.
new-item "My Documents" -Type Directory cd "My Documents" new-item "Test Scripts" -Type Directory cd "Test Scripts" new-item "PowerShell Book" -Type Directory cd "PowerShell Book"
As you can see in Figure 19-22, information about each new folder is displayed as it is created.
Figure 19.22. Figure 19-22
To create the new drive called Book and display some of its properties, use the following command:
new-psdrive -Name Book -PSProvider FileSystem -Root "C:\My Documents\Test Scripts\PowerShell Book" | format-list
Be careful not to include a colon character in the drive name in the preceding command. The value of the Provider parameter specifies that the FileSystem provider is used ...
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.