Changes

Working with File Systems in Windows PowerShell 1.0

3,046 bytes added, 15:53, 5 December 2008
New page: Given that Windows PowerShell is primarily targeted at easing the job of system administrators there is a good chance that part of developing scripts is going to involve interacting with W...
Given that Windows PowerShell is primarily targeted at easing the job of system administrators there is a good chance that part of developing scripts is going to involve interacting with Windows files and file systems. This chapter will focus on working with file systems with Windows PowerShell, while the next chapter, entitled [[Working with Files in Windows PowerShell]], will cover working with the contents of individual files.

== Windows PowerShell File System Cmdlets ==

Windows PowerShell provides a collection of cmdlets specifically for the purposes of interacting with file systems. Each command is accessible in a number of different ways:

* '''Cmdlet name''' - The standard cmdlet name, such as ''Get-Location''.

* '''Alias''' - An preconfigured, abbreviated alias for the cmdlet name such as ''gl'' for ''Get-Location''.

* '''cmd.exe command''' - The cmd.exe equivalent command to help users familiar with the Windows Command Prompt migrate to PowerShell.

* '''UNIX/Linux sh command''' The UNIX/Linux shell equivalent command to help user migrate skills to Windows PowerShell.

The following table lists the key file system related cmdlets together with the various alternate methods of accessing each one:

<table border="1" cellpadding="5" cellspacing="0" id="E3B" style="border-collapse: collapse; border-color:#cccccc; border-style: solid; border-width: 1px; margin-bottom:20px">
<tr bgcolor="#cccccc" style="color:black" valign="top">
<th>
<p>Cmdlet Name</p>
</th>
<th>
<p>Alias</p>
</th>
<th>
<p>Cmd Command</p>
</th>
<th>
<p>UNIX sh Command</p>
</th>
<th>
<p>Description</p>
</th>
</tr>
<tr>
<td>
Clear-Item</td> <td>cli</td> <td>N/A</td> <td>N/A</td> <td>Clears content of a file
</td>
</tr>
<tr bgcolor="#e9e9e6">
<td>
Copy-Item</td> <td>cpi</td> <td>copy</td> <td>cp</td> <td>Copies file or folder
</td>
</tr>
<tr>
<td>
Get-Content</td> <td>gc</td> <td>type</td> <td>cat <td>Gets the content of a file
</td>
</tr>
<tr bgcolor="#e9e9e6">
<td>
Get-Location</td> <td>gl</td> <td>cd</td> <td>pwd</td> <td>Gets the current directory
</td>
</tr>
<tr>
<td>
Move-Item</td> <td>mi</td> <td>move</td> <td>mv</td> <td>Moves file or folder
</td>
</tr>
<tr bgcolor="#e9e9e6">
<td>
New-Item</td> <td>ni, md</td> <td>N/A</td> <td>N/A</td> <td>Creates file or folder
</td>
</tr>
<tr>
<td>
Remove-Item</td> <td>ri</td> <td>del, rd</td> <td>rm, rmdir</td> <td>Deletes file or folder
</td>
</tr>
<tr bgcolor="#e9e9e6">
<td>
Rename-Item</td> <td>rni, rn</td> <td>ren</td> <td>mv</td> <td>Renames file or folder
</td>
</tr>
<tr>
<td>
Set-Content</td> <td>sc</td> <td>N/A</td> <td>N/A</td> <td>Sets file content
</td>
</tr>
<tr bgcolor="#e9e9e6">
<td>
Set-Item</td> <td>si</td> <td>N/A</td> <td>N/A</td> <td>Sets file content</td>
</td>
</tr>
<tr>
<td>
Set-Location</td> <td>sl</td> <td>cd, chdir</td> <td>cd, chdir</td> <td>Sets current directory
</td>
</tr>
</table>