Changes

Working with File Systems in Windows PowerShell 1.0

1,485 bytes added, 20:15, 5 December 2008
Creating New Windows PowerShell Drives
== Creating New Windows PowerShell Drives ==
 
In addition to providing access to system drives, Windows PowerShell provides the ability to create PowerShell Drives (''PSDrives'') which provide short cuts to directories on physical file systems. For example, it is possible to create a PSDrive which can be used to reference a particular directory on a file system. For the purposes of demonstrating this feature, we will create a temporary directory on the current file system called ''/tmp/myfiles'':
 
<pre>
PS C:\Users\Administrator> md /tmp/myfiles
 
 
Directory: Microsoft.PowerShell.Core\FileSystem::C:\tmp
 
 
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 12/5/2008 12:08 PM myfiles
</pre>
 
Now that the directory exists we can map it to a PSDrive using the name ''tmpfiles'' as follows:
 
<pre>
PS C:\Users\Administrator> new-psdrive -name tmpfiles -psprovider filesystem -root (resolve-path /tmp/myfiles)
</pre>
 
Now that the PSDrive is configured, it is possible to use it much as we would any other filesystem:
 
<pre>
PS C:\Users\Administrator> "This is a test" > tmpfiles:/test.txt
 
PS C:\Users\Administrator> dir tmpfiles:/test.txt
 
 
Directory: Microsoft.PowerShell.Core\FileSystem::C:\tmp\myfiles
 
 
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 12/5/2008 12:12 PM 34 test.txt
 
 
PS C:\Users\Administrator> get-content tmpfiles:test.txt
This is a test
</pre>